sub num_or_str { no warnings 'numeric'; $_[0] <=> $_[1] || $_[0] cmp $_[1] } my @sorted = sort num_or_str( $people{$a}->{age}, $people{$b}->{age} ), keys %people;