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