last if $top--;
In your first example this would evaluate to 'last if true', thus exiting the loop before the first print statement would get called.
Shouldn't that be last unless $top--; or am I overlooking something?
Re^2: Top five words by occurrence
Download Code Replies are listed 'Best First'.