# an array of terms used to create hash1 my @terms = ( 'male','female','child' ); # hash1 of term arrays my %terms = (); $terms{1} = [ 'male' ]; $terms{2} = [ 'female' ]; $terms{3} = [ 'child' ]; $terms{4} = [ 'male', 'female' ]; $terms{5} = [ 'male', 'child' ]; $terms{6} = [ 'female', 'child' ]; $terms{7} = [ 'male', 'female', 'child' ]; # hash2 of term occurrences my %occurs = (); $occurs{111} = [ 'male' ]; $occurs{112} = [ 'male' ]; $occurs{113} = [ 'male', 'child' ]; $occurs{114} = [ 'female' ]; $occurs{115} = [ 'child', 'female' ]; #### my %tally = (); # Male on its own appeared twice $tally{hash1_terms1} = 2; # Female on its own appeared once $tally{hash1_terms2} = 1; # Child on its own appeared twice $tally{hash1_terms3} = 0; # and so on...