in reply to comparing values of o hashes

I want to compare the genotypes of two hashes when the chromosome and position match.

Within one hash, is it possible for two or more records to have the same chromosome and position? If not, you might change your underlying record structure to a hash of genotypes, keyed by a merged string of chromosome and position. Something like this:

$gen_seq_list{'42-MG-BA'} = ( '19_35770059' => 'TC', '2_68019584' => 'G', '16_9561557' => 'G' );

And then perhaps:

for my $seq (keys %$gen_seq_list) { for (keys %{$seq}) { if ($gen_seq_list{$seq}{$_} == $cave_snp_list{$seq}{$_}) { ... } } }

Another thought is to build one hash instead of two like this:

use strict; use warnings; my %genes = ( '42-MG-BA' => { '19_35770059' => { cave => 'TC', gen => 'AA' }, '2_68019584' => { cave => 'G' }, '16_9561557' => { gen => 'AG' }, }, '41-OK-DZ' => { '7_158773210' => { gen => 'AA', cave => 'G'}, }, ); for my $gene (keys %genes) { for my $seq (keys %{$genes{$gene}}) { my $href = \%{$genes{$gene}{$seq}}; if (keys %$href > 1) { print "$gene:$seq:", join(",", map {"$_=$$href{$_}"} keys %$href), "\n"; } } } __OUTPUT__ 41-OK-DZ:7_158773210:gen=AA,cave=G 42-MG-BA:19_35770059:gen=AA,cave=TC