There is a string(just for testing) and I want to replace all instances of <p>
under the div, <div id="text">
. How do I do that ?
I tested with m
and s
modifiers, but in vain (Only the first one gets replaced). I have given my Perl code below :
#!/usr/bin/perl
use strict;
use warnings;
my $string = <<STRING;
<div id="main">
hellohello
<div id="text">
nokay.
<p>This is p1, SHUD B replaced</p>
Alright
<p>This is p2, SHUD B replaced</p>
Yes 2
<p>this is P3, SHUD B replaced</p>
Okay done
bye
</div>
bye
<p>this is not under the div whose id is text and SHUDN'T b replaced</p>
</div>
STRING
my $str_bak = $string;
print "Sring is : \n$string\n\n";
$string =~ s/(<div id="text">.*?)<p>(.*)(<\/p>.*?<\/div>)/$1<p style="text-align:left;">$2 $3/sig;
print "Sring now is : \n$string\n\n";