print map $_->[2], sort { $a->[1] cmp $b->[1] or $a->[0] <=> $b->[0] } map [ $_, $hash2{$_}{'key'}, "key $_ and $hash2{$_}{'key'}\n" ], keys %hash1;