in reply to string substitution

Whitespace is contained in [^\w]. Maybe you want to use \S instead of [^\w]? Or, if you just want to remove all spaces, why don't you use s/\s//g?

Replies are listed 'Best First'.
Re^2: string substitution
by Gosh (Initiate) on Dec 04, 2010 at 11:23 UTC
    Thanks for answer. This regexp does the thing: s/(\W)\s+/$1/g

      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.
      True laziness is hard work