### Open a handle on a string, read it line-by-line, then close it: $SH = new IO::Scalar \$data; while (defined($_ = $SH->getline)) { print "Got line: $_"; } $SH->close; #### 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 );