my %matches = map {/(.*)/, 1}, do {local @ARGV = "file1"; <>}; local @ARGV = ("file2", "file3", "file4", "file5"); while (<>) { /^(\S+)/ && $matches{$1} && print }