in reply to stripping everything but numbers and letters

As you have + inside your character class, it will not be replaced.

my $s = 'abc123+'; $s =~ s/[^0-9+]//g;

Maybe you wanted a quantifier, which should be placed directly after the character class.

$s =~ s/[^0-9]+//g;

You can also use tr///:

$s = 'abc123+'; # remove any non-digit $s =~ tr/0-9//cd; # or remove any non-alphanumeric $s =~ tr/A-Za-z0-9//cd;

See perldoc perlop for details (Search for 'tr/SEARCHLIST/REPLACEMENTLIST/cds' ).

Update

  1. removed /s from tr/// code; thanks jwkrahn

Replies are listed 'Best First'.
Re^2: stripping everything but numbers and letters
by jwkrahn (Abbot) on Feb 06, 2009 at 12:10 UTC

    Using the /s option with /d makes no sense.   You can't Squash something that has been Deleted.

      Thanks. Code is modified accordingly.

Re^2: stripping everything but numbers and letters
by cdarke (Prior) on Feb 06, 2009 at 11:42 UTC
    As you have + inside your character class, it will not be replaced

    Works for me:
    my $var = 'abcdef56+67jkkjk'; $var =~ s/[0-9+]//g; print "$var\n";
    Gives:
    abcdefjkkjk

      Did you notice, that my code uses a negated character class?

      If the character class is not negated, the + is replaced; if the class is negated, it is not.