in reply to Re^4: search and replace
in thread search and replace

#!/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>
The output should be
<root <con> <p>This is para1</p> <p>This is para2</p> </con> </root>
Only after the last p tag in the file I have to add </con>

Replies are listed 'Best First'.
Re^6: search and replace
by gmargo (Hermit) on Nov 05, 2009 at 16:54 UTC

    That is different from what you asked for in the other thread: Set the flag! Which is it?