my $idx = firstidx { $_ == $target } @a; splice(@a, $idx, 1) if $idx >= 0;