Assuming the hash is
[ user1 => 2,
user2 => 3,
user3 => 6,
user4 => 4,
.
.
.
]
This will loop through the hash, greatest num of processes running to the least, exit the loop, once all users with >=4 processes have been processed.
foreach my $key (reverse sort {$hash{$a} <=>...