in reply to help querying a hash

duff is right on, wrt mapping each id to its fruit class.
Now let's talk about the rest of the problem: checking all the input data, and printing the count summary.

It appears that you don't actually start with a hash, but with two arrays, parallel - one for key, one for value. Converting that into a hash is a mistake, unless you don't care about counts. But you do. So let's just iterate over the input data directly:

my( @keys, @values ); # wherever they come from. @keys == @values or die "input arrays not same length!"; my %fruit_map; # and populate as [duff] showed. my %pair_count; # accumulate results for my $i ( 0 .. $#keys ) { my $k = $fruit_map{ $keys[$i] }; my $v = $fruit_map{ $values[$i] }; $pair_count{"$k-$v"}++; } # now show results: for ( sort keys %pair_count ) { print "$_: $pair_count{$_}\n"; }

You can achieve some degree of retaining the input order in the output by tie'ing %pair_count to Tie::IxHash.

We're building the house of the future together.