#your code #my $infile = $ARGV[0]; #my $infile2 = $ARGV[0]; <--- $infile == $infile2 #corrected code my $infile = $ARGV[0]; my $infile2 = $ARGV[1]; #### #yourcode while (){ chomp; my @line = split ('\t', $_); my $key1 = 'A' . $line[0] . '.' . 'A' . $line[1]; ##first key my $key2 = 'A' . $line[1] . '.' . 'A' . $line[0]; ##key the other +way ##check to see if the key exists in the hash ##if it doesn't there is data in your infile, not in you names ar +ray if (exists $diplotypes{$key1} && $line[0] <= $line[1]) { $diplotypes{$key1} += $line[2]; } elsif (exists $diplotypes{$key2} && $line[0] >= $line[1]) { $diplotypes{$key2} += $line[2]; } else{##world is out to get you print STDERR "No key for $key1 or $key2\n"; next; } } #### while (){ chomp; my @line = split ('\t', $_); my $key1 = 'A' . $line[0] . '.' . 'A' . $line[1]; ##first key my $key2 = 'A' . $line[1] . '.' . 'A' . $line[0]; ##key the other way ##check to see if the key exists in the hash ##if it doesn't there is data in your infile, not in you names array ##new logic if($line[0] <= $line[1]) { if(exists $diplotypes{$key1}) { $diplotypes{$key1} += $line[2]; } else { #key doesnt exist so add it $diplotypes{$key1} = $line[2]; } } else { if(exists $diplotypes{$key2}) { $diplotypes{$key2} += $line[2]; } else { #key doesnt exist so add it $diplotypes{$key2} = $line[2]; } } }}