use 5.12.4; use strict; use warnings; my %wordcount; open(FILE, "names.txt") or die "Could not open file: $!"; while(my $line = ) { chomp($line); my @words = split(' ', $line); foreach my $word(@words) { $wordcount{$word} += 1; } } sub hashDescend { $wordcount{$b} <=> $wordcount{$a}; } foreach my $key (sort hashDescend (keys(%wordcount)) { print "Word: $key \t\t\t\t\t\t Count: " . ($wordcount{$key}) . "\n"; }