for my $i (0..$#a) { my $s = $a[$i]; $s =~ s/x//g; push @b, $s if $s; }