while (<$fh1>) { # Reading first hash my ($id, undef, undef, undef, $seq) = split; if ( exists $bow1{$ID} ){ warn "ID \'$id\' already exists for hash 1!\nThe current sequence value is \'$bow1{$id}\', which would be replaced with \'$seq\'.\n"; .... handle the error better (maybe ignore if sequences are the same?) .... next; ## skip it } $bow1{$id} = $seq; } close $fh1 || die "Failed to close $file1 : $!";