while ($line = ) { print OUTPUT1 "$filename\n" if (exists($hash1{$entry})); print OUTPUT2 "$filename\n" if (exists($hash2{$entry})); }