# /usr/bin/perl -w # Created: 2016-06-16 my %freq_hash; # Collect frequency counts, of the form # # 999 [thing] while (<>) { next unless m/(\d+) (\w+)/; $freq_hash{$2} += $1; } # Print in descending order by frequency. foreach my $word (sort { $freq_hash{$b} <=> $freq_hash{$a} } keys %freq_hash) { print $freq_hash{$word} . ' ' . $word . "\n"; }