$counts{$_}++ for @array_of_numbers; my @sorted_array = sort { $counts{$a} <=> $counts{$b} } keys %counts;