Here's a solution that does what you're after. The substitution is:
s{\[\[(.*?)\]\]}{$1 =~ s/ /_/gr}e
I've added an additional test to check that various embedded brackets do not cause issues.
$ perl -Mstrict -Mwarnings -E ' my $x = q{Here are [[a variable number of words]] in brackets}; say $x; $x =~ s{\[\[(.*?)\]\]}{$1 =~ s/ /_/gr}e; say $x; my $y = q{Here are [[a variab]le number [ of ] wo[rds]] in brackets}; say $y; $y =~ s{\[\[(.*?)\]\]}{$1 =~ s/ /_/gr}e; say $y; ' Here are [[a variable number of words]] in brackets Here are a_variable_number_of_words in brackets Here are [[a variab]le number [ of ] wo[rds]] in brackets Here are a_variab]le_number_[_of_]_wo[rds in brackets
-- Ken
In reply to Re: substitute characters in the RHS of a search & replace
by kcott
in thread substitute characters in the RHS of a search & replace
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |