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


in reply to Split on Blank Line into array, and keep the blank line in the array

Please use code tags. See Markup in the Monastery for details.

How do you want to treat the blank lines?

Maybe you need to read blockwise?

#!/usr/bin/perl -l use strict; use warnings; { local $/ = ""; my @blocks = <DATA>; local $, = "\n"; print map { ">>>$_<<<" } @blocks; } __DATA__ AB A BB CC C CD EE EA

Maybe you want to capture the split pattern?

#!/usr/bin/perl -l use strict; use warnings; my $content = do { local $/; <DATA> }; my @blocks = split /(\n\n+)/, $content; { local $, = "\n"; print map { ">>>$_<<<" } @blocks; } __DATA__ AB A BB CC C CD EE EA