my %freq = ...; my @array = qw[ data items here ]; my @ordered = sort{ $freq{ $b } <=> $freq{ $a } } @array; ## for highest frequency first.