in reply to Trouble in text manipulation
From the input(a.xml) it seems that you are handling XML file. Its better to use XML modules to fiddle with XML rather than with regular expressions.
Kindly take a look at XML::Twig. You can use XPATH expressions to access the elements/attributes as you wish.
use perl for(;;);