in reply to How to do multiple substitutions with one RegEx?
As already said, when you specify eval (/e), you can use any valid Perl code for the substitution, such as string concatenation.
In the special case here (i.e. upper-casing), and because the substitution side by default acts like a double quoted string, you could also make use of \U...\E and just interpolate $1 and $2, so you don't need eval.
Both of these variants would produce "WELCOME foo AAAAA" with your input:
$string=~s/([b-w]+)[^a]+([a]+)/uc($1)." foo ".uc($2)/ge; $string=~s/([b-w]+)[^a]+([a]+)/\U$1\E foo \U$2\E/g; # without /e
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to do multiple substitutions with one RegEx?
by vennila (Novice) on May 06, 2010 at 07:38 UTC |