my @array = (1, 2, 3, 4, 2, 1, 2, 0, 1, 0, 0); for my $i (0 .. $#array) { unshift @array, splice @array, $i, 1 if $array[$i] == 0; }