my @array=qw(a b c d e); my $num = 13; # so every element should get 2 = int(13/5), with the # remaining 3 given to the first three (or randomly). # Desired result: my %result = (a=>3, b=>3,c=>3,d=>2,e=>2);