my @new_a; for my $i (0..$#a){ push (@new_a, $a[$i]) unless is_unwanted($a[$i]); } @a = @new_a; @new_a = ();