#!/usr/bin/perl # # use strict; use warnings; my $file = "file.log"; open ( IN, $file ) || die "Can't open $file $!"; my %position; while ( ) { chomp; $position{$.+1} = tell(IN); #I don't quite grasp this part yet # $. holds line number if ( /first_string/ ) { my $count = 0; #bad way of only finding 2nd string once print "$. $_\n"; seek IN, $position{$.+1}, 0; while ( ) { chomp; if ( ( $_ =~ /2nd_string/ ) && ( $count < 1 ) ) { print "found 2nd string\n"; $count += 1; } } } seek IN, $position{$.+1}, 0; } close FILE;