sub keys_sorted_by_network { my $h = shift; sort { $h->{$a}{network} cmp $h->{$b}{network} } keys %$h; } my @result = keys_sorted_by_network($VAR1);