in reply to It seems simple...

The !~ operator negates the return value of the =~ operator, not of the regular expression. In an s/// operation, the result of $string will be the same regardless of whether !~ or =~ is used, as all that is being negated is the number of matches returned. What you're looking for is $string =~ s/\W|\s//g;

Replies are listed 'Best First'.
RE: Re: It seems simple...
by Xavier (Novice) on Feb 24, 2000 at 11:28 UTC
    Unfortionatly, that doesn't work.
    s/\W|\s//g;
    successfully does what it says it will - both:
    s/\W//g;
    and
    s/\s//g;
    thereby eliminating the whitespace that I wanted to preserve (both regular expressions do that, actually)
      Sorry, I misread your question the first time (me having posted the first answer).. I think what you want is $string =~ s/[^\w\s]//g;
        Cool, that works. Thanks. The question now, though, is why? I know that: /^\w/ will match any word character at the start of a line and that /[]/ is character class stuff. Does the ^ actually negate or something similar instead of match the start of a line (in this context, of course)?
        Now that I know what to look for, I finally found the explanation in man perlre . Ah, well. someday i'll read that in its entirerty.