... my @words = split /\W+/; ... #### foreach $w ( ( sort { $count{$b} <=> $count{$a} } keys %count ) [0..4] ) { ... }