foreach my $line ( split("\n", $txt) ) { # do something to filter $line }