while ($mmap =~ m/$pat/omg) { my $pos = pos $mmap; # Find the beginning and end of this line my $first = rindex($mmap,"\n",$pos)+1; my $last = index($mmap,"\n",$pos)+1; print substr($mmap,$first,$last-$first); }