in reply to Inserting numbers between parenthese matches in regexp
A second approach to the one mentioned above is to exploit the power of the /e modifier, which turns the right-hand side of the substition into a first-class expression. Then you could do something like:
s/([a-m])([n-z])/$1 . myfunction($1, $2) . $2/eg; sub myfunction { my ($pre, $post) = @_; # we could do something smart with the pre- and post- # strings, but instead we'll just return a 5. return 5; }
|
|---|