my $found=0; while() { chomp; if (exists($update_words{$_})) { print "found $_ \n"; $found=1; } } if (not $found) { print "not found $_ \n"; #write } #### while (<$fh>) { chomp; my $comparevalue= split(/,/,$_); $update_words{$comparevalue}= $_; print "$_\n"; } ... while() { chomp; my $comparevalue= split(/,/,$_); if (exists($update_words{$comparevalue})) { print "found $_ \n"; $found=1; print OUTFILE $update_words{$comparevalue} } else { print OUTFILE $_; } }