#! perl -slw use strict; my %hash; ++$hash{ <> } until eof(); my @top5; for( keys %hash ) { for my $i ( 0 .. 4 ) { if( !defined( $top5[ $i ] ) or $hash{ $_ } > $hash{ $top5[ $i ] } ) { splice @top5, $i, 0, $_; pop @top5 if @top5 > 5;; last; } } } print @top5; __END__ many hardships a million dollars love life apple pie you attempt things