open my $fp, '<', $file or die $!; while (<$fp>) { my $line = $_; if ($line =~ /$regex/) { # How do I find out which line number this match happened at? } } close $fp;