http://www.perlmonks.org?node_id=764495


in reply to question on multi line pattern matching for html formatting

The first reply addresses doing this right way, I'll go ahead and show you how to do it the wrong way, using line matching like you tried. We'll achieve the same effect though.
#!/usr/bin/perl -l use strict; use warnings; my $file; { local $/ = undef; $file = scalar <DATA>; } ## Find me two newlines or be the start of the file ## Followed by any amount of newlines ## Followed by one or more characters (our capture, your paragraph) ## Followed by any amount of newlines ## Followed by any two newlines or the end of the file ## Flags: treat the file as one line, continue search for more paragra +phs (/g in list context) while ( $file =~ m/ (?>\n{2}|\A) \n* (.+?) \n* (?=\n{2}|\z)/sxg ) { print "<p>$1</p>"; } __DATA__ Paragraph one is this Paragraph two is this Paragraph three is this Paragraph three and this But stops here and doesn't get the rest of the newlines


Evan Carroll
The most respected person in the whole perl community.
www.EvanCarroll.com