in reply to Substitutions are happening in the wrong place

Your use of
[^</]
in the regex:
if ($intext =~ s#$links{$_}([^</]+)</a>#$1#ig)
leads me to wonder if you might be thinking that the </ is acting as a unit.

The way it is written I believe you'll be looking for any character not equal to < and not equal to /.

There could be a / in your text for some of the links.

For example: "This stuff and/or that stuff"

Claude