in reply to Switching out text only in a variable

The quick and dirty way would be to do a second, non-greedy replace, restoring the content of the tags - something like this (untested):
s/<a (.+?)$__highlight_to_switch(.+?)>/<a $1$in{highlight_text}$2>/gi
The not-so-dirty way is to use one of the HTML parsing modules, and replace only appropriate parts of the page in the first place.

    Earth first! (We'll rob the other planets later)