in reply to Calling a function in regex substitution
If you want to replace all matches, you'll have to specify the /g flag too.
$str=~s/(iteration)(.*)/<B> \U$1\E$2 <\/B>/g;
You can run code in the substitution part by specifying the /e flag, but you'll have to make sure the whole string on the right is valid Perl code. You can't mix and match literal strings and executable code.
$str=~s/(iteration)(.*)/"<B> ".uc($1).$2." <\/B>"/ge;
The next works too, it's one of the few tricks available to embed executable code in a double-quoted string.
$str=~s/(iteration)(.*)/<B> @{[uc($1)]}$2 <\/B>/g;
|
|---|