in reply to next statement logic

You don't need the last next statement. You code could be like this:

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

Can't figure out why you are printing in the end of the loop...

Hope this helps.

Igor 'izut' Sutton
your code, your rules.