my $total_words = @words; #All word count my %count; $count{$_}++ for @words; # Here are the counts my $uniq_words = scalar keys %count; # Nš of uniq words # Print sorted by frequency print "$_\t$count{$_}" for (sort { $count{$b} <=> $count{$a} } keys %count);