sort { $hash2{$a}{key} cmp $hash2{$b}{key} || $a <=> $b } keys %hash2