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

fletcher_the_dog has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I have files that have some special markers in them something like this:
<5b>I <5c>like <5d>tacos
I was wondering if there was anyway possible to make the regex engine ignore these tags without deleting them? For example, if I had a regex like this:
s/(\w+)\s+tacos/$1 yummy tacos/g;
I would want it to change the above phrase to:
<5b>I <5c>like yummy <5d>tacos
I realize I could change the regex to:
s/(\w+)\s+(<\w\w>)?tacos/$1 yummy $2tacos/g;
but my script requires quite a few complicated regexes substitutions and having optional "(<\w\w>)?"s everywhere will make the regexes very ugly and make it hard to keep track of which capturing parenthesis are catching what.
I was wondering if there was a way to make the regex engine see the a string something like this where it would do its matching just against the first element in each sub array:
$string = [ ['I','<5b>'], [' '], ['l','<5c>'], ['i'], ['k'], ['e'], [' '], ['t','<5d>'], ['a'], ['c'], ['o'], ['s'] ]
Another possibilty I have considered and tried was erasing all the tags and then after I was done with all the substitutions doing a diff and trying to reconstruct where the tags should go. This actually works but was way too slow.