http://qs1969.pair.com?node_id=719123


in reply to Replace after match in regex (key value subsitution)

Although others have pointed out that there is a nice one-pass approach to your problem, it is possible to access the location of a match after the match itself:
my $a = 'abc'; $a =~ /(b)/; substr($a, $-[1], $+[1] - $-[1], 'B'); print $a, "\n"; # aBc
See perlvar.