Multiline Strings in Perl


If you want to introduce multiline strings into your programs, you can use the standard single quotes as below −

Example

 Live Demo

#!/usr/bin/perl
$string = 'This is
a multiline
string';
print "$string\n";

Output

This will produce the following result −

This is
a multiline
string

You can use "here" document syntax as well to store or print multiline as below −

Example

 Live Demo

#!/usr/bin/perl
print <<EOF;
This is
a multiline
string
EOF

Output

This will also produce the same result −

This is
a multiline
string

Updated on: 28-Nov-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements