while ($line = ){ chomp $line; if (exists $hash1{$entry}) { print OUTPUT1 "$filename\n"; #I do not have a next statement here #because i want to continue #checking if this entry also exists #in hash2... } if (exists $hash2{$entry}) { print OUTPUT2 "$filename\n"; next; } print OUTPUT1 "$filename\n"; next; } close(MAIN_FILE1)