in reply to Re: string substitution
in thread string substitution

Thanks for answer. This regexp does the thing: s/(\W)\s+/$1/g

Replies are listed 'Best First'.
Re^3: string substitution
by GrandFather (Saint) on Dec 06, 2010 at 20:14 UTC

    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