http://www.perlmonks.org?node_id=922557

heeru has asked for the wisdom of the Perl Monks concerning the following question:

Hi Experts, I have the following code (which parses through a file) looking for particular text.
$fileName = shift; open(HND, $fileName) or die "Can't open $fileName: $!"; @fileArr = <HND>; close(HND); foreach my $line ( @fileArr ) { $line =~ s/<bindpass>welcome<\/bindpass>/<bindpass>Welcome1<\/ +bindpass>/g; } open(HND, ">$fileName") or die "Cant open for writing $fileName: $!" +; print HND @fileArr; close(HND);
This works perfectly fine and replaces all occurrences in the file correctly. Issue here is, the third time this text appears, it appears after a line, lets say,  <bindname>abcde<\/bindname> . I do not want the occurrence to change in this case. So how can I include this in my code? Help appreciated. Thanks !