for my $key ( keys %doublet ) { if ( exists( $triplet{$key} )) { # need to check values next if ( $doublet{$key}[0] eq $triplet{$key}[2] and $doublet{$key}[1] eq $triplet{$key}[1] ); } # get here if $key does not exist in %triplet, # OR if $triplet{$key} is not equivalent to $doublet{$key} print "$key\n"; }