for my $inner ( ( values %$outer )[ order_of_sorted keys %$inner ] ) { # ^^^^^^^ Correct. ^^^^^^^ Oops.