while ($str =~ /$pattern/g) { my $loc = tell($fh) - length($str) + pos($str) - length($pattern); print "Found a match starting after $loc.\n"; }