That's probably not doing what you want, at least according the your original problem specification which called for removing spaces between, rather than after, characters. Consider:
use strict; use warnings; my $str = "The quick & the dead."; $str =~ s/(\W)\s+/$1/g; print $str;
Prints:
The quick &the dead.
In reply to Re^3: string substitution
by GrandFather
in thread string substitution
by Gosh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |