use strict ; use warnings ; my %count ; while( my $line = ) { my @words_in_this_line = split( /\s/, $line ) ; foreach my $word ( @words_in_this_line ) { $word = lc( $word ) ; next if( $word =~ /\d+/ ) ; if( defined( $count{ $word } ) ) { $count{ $word } ++ ; } else { $count{ $word } = 1 ; } } # End of loopint through words. } # End of looping through lines in file. my @uniq_words_in_file = keys %count ; @uniq_words_in_file = sort( { $count{$b} <=> $count{$a} || $a cmp $b } @uniq_words_in_file ) ; foreach my $word ( @uniq_words_in_file ) { print "'$word'\tOccurred\t$count{ $word }\ttimes\n"; } __DATA__ This these that the and how who writ this code 1 how now brown cow 1asdf 23 the fox jumped into 123 the hencoop the lazy brown 2134 dog was azleep.