while(<$fh>) { # Make a note of the line length # in case we need to rewind $fh my $line = length; chomp; # ... if ( /^\d-RECORD$/ ) { # rewind $fh to the beginning of # the current line, so <$fh> can # re-get it. seek( $fh, 0 - $line, 1 ); last; } # ... }