foreach my $loc (sort {${$b}{online} <=> ${$a}{online}} @locations) { print "${$loc}{online} ${$loc}{users} $loc\n"; }