for my $idx (reverse 0 .. $#array) { my $item = $array[$idx]; if (some_test($item)) { splice(@array, $idx, 1); # remove the element } } #### while (@work) { my $item = shift/pop @work; # Possibly push/unshift items onto @work }