for my $outer (keys %$hash) { my $subhash = $hash->{$outer}; for my $inner (sort { $a <=> $b } keys %$subhash) { # iterating over the sorted values } }