in reply to best way to print paragraphs of text

If you want to pretty indent the heredoc contents so that they are indented within the if clause, you can get most of the way there with the following code:

if (1) { (my $sOutput = <<'OUTPUT') =~ s/^\s+|\n(?!\s+\n)//gm; Today is Monday, my favorite day of the week. It is my favorite day because Jerry said "Monday is the best day of the week". Tuesday is my second-favorite day. Why can't all days be as great as Monday? Who knows. This is a second paragraph. OUTPUT print "$sOutput\n"; }

which outputs

Today is Monday, my favorite day of the week.It is my favorite day bec +ause Jerry said "Mondayis the best day of the week". Tuesday is my s +econd-favorite day.Why can't all days be as great as Monday? Who kno +ws. This is a second paragraph.

You'll still need to keep OUTPUT at the start of the line (unless you chose to use whitespace in your end of here-doc marker as JavaFan suggests below), but at least you can indent the remainder of the text. The regular expression s/^\s+|\n(?!\s+\n)//gm removes leading whitespace on all lines. It merges together all lines that have only 1 newline between them and collapses a run of blank lines into a single newline. If instead you want to keep the line breaks exactly as shown in the heredoc, you can use a slightly different regular expression: s/^[^\S\n]+//gm, which results in the output:

Today is Monday, my favorite day of the week. It is my favorite day because Jerry said "Monday is the best day of the week". Tuesday is my second-favorite day. Why can't all days be as great as Monday? Who knows. This is a second paragraph.

For more information and other neat tricks you can do with here-documents, see perlop and search for "here-doc".

Best, beth

Update 1: added example that preserves line breaks.

Update 2: corrected my post with a parenthetical comment refering to JavaFan's post below.