sub countcomb { my $nwordsatonce = shift; my ($k,$v); my %totals = (); local $" = ' '; # just in case while (($k,$v) = each %Items) { next unless $nwordsatonce <= @$v; do {$totals{"@$_"} += 1;} for combine($nwordsatonce,sort @$v); } my @comb = sort {$totals{$b} <=> $totals{$a} or $a cmp $b} keys %totals; my $topn = 5; my $toptot = $totals{$comb[$topn-1]}; while ($toptot <= $totals{$comb[$topn]}) {$topn++;} print "Top $nwordsatonce - word combinations: (cuttoff $toptot)\n"; do {print "$_ ($totals{$_})\n";} for @comb[0..$topn-1]; }