http://qs321.pair.com?node_id=11119208


in reply to Modifying muliple matched strings in text

Hint:

Call a function in the substitution part (activated by /e modifier) which returns your transformation.

s/PATTERN/replace($1,$2)/eg

Not sure if you even need to pass the matchgroups $1,... into the sub, but it's certainly more readable.

Edit

Pattern should match the links [$1]($2) (pseudo syntax).

I recommend using the /x flag for readability.

The transformations of $2 should happen inside the replace() sub

HTH!

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Modifying muliple matched strings in text
by nysus (Parson) on Jul 14, 2020 at 13:24 UTC

    Very cool. Didn't know that was even possible (well probably read about it once and then forgot). Thanks.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks