http://www.perlmonks.org?node_id=475809


in reply to Top five words by occurrence

Two things - first, it'd be handy to have your sample input as well. Second, what you probably want to do is continue using split, but then just clear off all trailing punctuation:

foreach my $wd (@words) { $wd =~ s/[[:punct:]]+$//; next if length($wd) < 5; $count{$wd}++; }
This will remove trailing apostrophes, such as "wha' zup?", but not ones in the middle of words, such as "ain't".

Oh, I lied - three things. Use strict and warnings. Just do. I added a "my" to the foreach above for strictness purposes - do the same for your other foreach.

Once you have all this, you should be able to sort on value, foreach my $w (sort { $count{$a} <=> $count{$b} } keys %count) { ... } to get everything in order. What you do with it after that depends on how you want to deal with multiple words in 5th place.

PS: best use of split with no parameters I've ever seen. I don't think that's even close to your problem, but is, in fact, the best part of your code. Good job. :-)