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


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

How about:

$$text_ref =~ s|(?<="http://)(.*?)(?=["/])|$fixers{$1} ? $fixers{$1} + : $1|ge ;

which does one scan of the input. This may be an advantage if you have a lot of fixers. But, if there are a lot of things that match, but don't require fixing, doesn't work so well.

the more complicated:

my $what = join('|', map(quotemeta, keys %fixers)) ; $$text_ref =~ s!(?<="http://)($what)(?=["/])!$fixers{$1}!ge ;
also does just the one scan and hits only the fixers.