use strict; use warnings; my @occurances = ( [ 'male' ], [ 'male' ], [ 'male', 'child' ], [ 'female' ], [ 'child', 'female' ], [ 'female', 'child' ], [ 'female', 'male', 'child' ], ); my @terms = ( [ 'male' ], [ 'female' ], [ 'child' ], [ 'male', 'female' ], [ 'male', 'child' ], [ 'female', 'child' ], [ 'male', 'female', 'child' ], ); my %tally; foreach my $array_ref ( @occurances ) { $tally{stringify(@$array_ref)}++; } foreach my $array_ref ( @terms ) { if ( defined $tally{stringify(@$array_ref)}) { print "Terms:" . join (" and ", @$array_ref) . " were found " . $tally{stringify(@$array_ref)} . " times\n" } else { print "Terms:" . join (" and ", @$array_ref) . " were found 0 times\n" } } sub stringify { join ("+", sort {$b cmp $a} @_) }