in reply to delete multiple occurrences

my $i = -1; my $p = 0; my @anew = map { $i++; !(/^z$/ or $p = 0) || !$p++ ? $a[$i] : () } @b;