for my $m (m/$regex/g) { # Update: reworked $matched{$m} = 1; print "$file $_"; }