my $hash = { foo => { one => 3 }, bar => { two => 6 }, baz => { three => 9 }, }; print join($/,sort { $b <=> $a } map { my $section = $_; map { sprintf("%5d %10s %s",$hash->{$section}{$_},$section,$_) } keys %{$hash->{$section}} } keys %$hash ) ,$/;