my %foo =( '11' =>{ '4'=>'Four', }, '33' =>{ '1'=>'One', }, '2' =>{ '2' => 'Two', }, ); my $ref_HoH = \%foo; my @sorted = sort { my $c = %{ $ref_HoH->{$a} }; my $d = %{ $ref_HoH->{$b} }; print "comparing $c to $d...\n"; $c <=> $d; } keys %$ref_HoH; __END__ comparing 1/8 to 1/8... comparing 1/8 to 1/8... comparing 1/8 to 1/8...