c:\@Work\Perl\monks>perl -wMstrict -le "my %hash1 = map { $_ => 1 } 1 .. 5; ;; my %hash2; $hash2{'1'}{key} = 'a'; $hash2{'2'}{key} = 'b'; $hash2{'3'}{key} = 'a'; $hash2{'4'}{key} = 'a'; $hash2{'5'}{key} = 'b'; ;; my @sorted_top_level_hash1_keys = map $_->[0], sort { $a->[1] cmp $b->[1] or $a->[0] <=> $b->[0] } map [ $_, $hash2{$_}{'key'} ], keys %hash1 ; print qq{sorted top-level %hash1 keys: (@sorted_top_level_hash1_keys)}; ;; for my $stlh1k (@sorted_top_level_hash1_keys) { print qq{key $stlh1k and $hash2{$stlh1k}{key}} } " sorted top-level %hash1 keys: (1 3 4 2 5) key 1 and a key 3 and a key 4 and a key 2 and b key 5 and b