To remove everything up to and including the first +, you can do:
$number ~= s/.*\+//;
If you want to keep the +, you can put that into the replacement:
$number ~= s/.*\+/+/;
The above says: Match "anything" (the .*
) followed by a +
(+
is a special character in regular expressions, which is why it needs the backslash escape) and replace it with nothing (or in the above example, replace it with a single +
).
Note that the above will strip out everything up to the LAST +
in the string, which may not be what you want. If you want to keep strip out everything up to the FIRST +
in a string, you can do:
$number =~ s/[^+]*\+//;
or
$number =~ s/[^+]*\+/+/; # Keep the +
The difference from the first regular expression being the [^+]*
instead of .*
, which means "match any character except a +
".
For more information on Perl's regular expressions, the perldoc perlre manual page is pretty good, as is O'Reilly's Mastering Regular Expressions book.