use warnings; use strict; my $string = "This is some text\nto be processed as\na file"; # use a zero-width positive look-behind assertion to split # the string on whatever is used as the input record # separator ($/) without consuming it foreach my $line ( split( m[(?<=$/)], $string ) ) { print $line; } # or, if you prefer the one-liner look print for split ( m[(?<=$/)], $string );