The output should be#!/usr/bin/perl use strict; use warnings; my $flag=0; while(<DATA>){ if($flag == 0){ if($_ =~ m/<p>/){ $_ =~ s/<p>/<con>/; $flag=1; } } print $_; } __DATA__ <root> <p>This is para1</p> <p>This is para2</p> </root>
Only after the last p tag in the file I have to add </con><root <con> <p>This is para1</p> <p>This is para2</p> </con> </root>
In reply to Re^5: search and replace
by Anonymous Monk
in thread search and replace
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |