foreach my $usrdir ( sort { scalar $hashref->{$b} <=> scalar $hashref->{$a} } keys %{$hashref} ) { ... }