# With "x" for my $i (0..$#count) { push @result, ($i) x $count[$i]; } #### # Without "x" for my $i (0..$#count) { for (1..$count[$i]) { push @result, $i; } }