Basically, what I'm trying to do is search through a rather large PHP file, and replace any block of PHP code that includes the string "search_term" somewhere in it with some other code. I.e.
<?php
//some stuff
?>
<?php
// some more stuff
$str = "search_term";
// yes...
?>
<?php
// last stuff
?>
should become
<?php
//some stuff
?>
HELLO
<?php
// last stuff
?>
What I've got so far is
$string =~ s/<\?php(.*?)search_term(.*?)\?>/HELLO/ims;
This correctly matches the closest closing ?>
, but begins the match at the very first <?php
, instead of the one closest to the string search_term
.
What am I doing wrong?