http://qs321.pair.com?node_id=658408


in reply to find and replace

If you're reading that line by line, you can't easily back up to make the replacement.

If you slurp the input, you need to save multiple matches for "affiliation" tags in a data structure and make another pass.

If your input is valid XML, then one of the XML modules may be the best approach.

After Compline,
Zaxo