In your previous post, I explained that the only reliable way to edit XML is to first parse it with a module from CPAN. The fact that you are already working on a similar problem should convince you that it is worth the effort to learn how. Your new question demonstrates the problem with "do it yourself" solutions. You encounter special cases where they do not quite work. Even if you devise a work around, you are still likely to find another special case, and then another and... Good Luck, Bill

This won't work for many cases. To start with, it won't work if the tags are <one> and </one>. In fact, you have to make a long series of assumptions about the input format and content and the way to process this data before you can hope this regex to work.

No, regex is the wrong approach here. Don't shoot a bullet into your own foot.