use strict; use warnings; open (my $fh, '<', '/usr/share/dict/words') or die "Unable to open words: $!"; while (1) { my $line = <$fh>; if ( $line =~ /^M....$/) { my $pos = tell($fh) - length($line); chomp $line; print "$line found\n"; # Go back to beginning of file (rewind) seek ($fh,0,0); # Now go and read that record again seek ($fh, $pos, 0); $line = <$fh>; chomp $line; print "$line found again!\n"; last; } } close ($fh);