while (<>) { $freq{$_}++ for split; } #### my $mode = $sorted_array[-1]; ## aren't negative indexes neat? #### .