in reply to Using undefined back-references?

Just add one extra character in the regexp:
while (s/<([^>]*)\s+ # Open tag, name and assorted crud. ($NMTEXT)="([^ >]*)" # Attribute and value (|\s+[^>]*)?\s+ # Optional assorted crud \2="([^ >]*)" # Repeated attribute and value /<$1 $2="$3,$5"$4/gx) { }
Notice the "Optional assorted crud" part.

Abigail