s/x//; # this could be written more efficient as tr[x][]d; #### my @b = map s/x//g ? $_ : (), @a; # Or: my @b = map tr/x//d ? $_ : (), @a;