in reply to How do I stop this from removing spaces?

TIMTOWTDI/Tangential observations (See the on-target discussions of interpolation by toolic, AnomalousMonk and Anonymonk, above):

Your asterisk, vertical_bar and questionmark are special chars in a regex; specifically, the "*" and "?" are quantifiers. So, since the asterisk appears first in your array, you're trying to feed the regex engine a quantifier without an antecedent; i.e., without anything to match.

So, another way around this would be to escape those characters that have special meaning in a regex; viz:

#!/usr/bin/perl use strict; use warnings; # 846423 my $id='TEST TEST foo|bar*test'; my @testdata = split(/ /, $id); print "Pre-regex: $id\n"; my @filename_filter=('\*', '\|', '<', '>', '\?', '/'); # $id =~ s/[@filename_filter]//g; for my $filename_filter(@filename_filter) { $id =~ s/$filename_filter//g; } print "post-regex: $id\n\n"; for my $testdata(@testdata) { for (@filename_filter) { my $regex = qr($_); $testdata =~ s/$regex//; } print "split&regex: $testdata\n"; }
prints:
Pre-regex: TEST TEST foo|bar*test post-regex: TEST TEST foobartest split&regex: TEST split&regex: TEST split&regex: foobartest

This appears to satisfy your spec without changing $", the $LIST_SEPARATOR. It IS the long way around, and not merely because my code goes out of it's way to be explicit, but perhaps addresses a closely related issue.

Update: corrected citation to refer to all the preceding, correct discussions of interpolation