my $lpos = tell(DATA); # remember where I was while () { print "$_"; if ($_ =~ /another/) { # if this line has what I want seek DATA, $lpos, 0; # rewind to beginning of line print ; # and read it again } $lpos = tell(DATA); # save offset to the beginning # of the next line } __DATA__ This is a line This is another line