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"; }