my @listofkeys = ('A','B','C'); @sortedlistofkeys = sort { $entry{$table}{$a}{RANK} <=> $entry{$table{$b}{RANK} } @listofkeys;