#on above $data i can split up the above string with each #Name tag followed by Phone tags associated with this my @namephn=map{m/.*?<\/Phone>/g } $data; print join "\n",@namephn; #---------- Output ------------- xyzabcd12345678955656556 UTVEFGH12345678955656556