in reply to Set the flag

It will be something like this, which turns $flag to 1 when it finds something:
my $foo = "This is a test."; my $flag = 0; print "$flag\t$foo\n"; $flag = ($foo =~ s/a/the/); print "$flag\t$foo\n";
But like irah says, you need to provide some code or data if you want more specific help.

Replies are listed 'Best First'.
Re^2: Set the flag
by Anonymous Monk on Nov 05, 2009 at 15:21 UTC
    #!/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>
    I have tried for the matching first <p>. But in a file how to find the last </p> tag and substitute.
    Please help me on this