in reply to Regular Expression Help Help

The code that you have shown does not say what values are assigned to the variables $location, $obj_name and $page, but I guess these are supposed to be, respectively, "1", "Stock3of1", and some string that is supposed to replace "\n<b>This is option Stock 3 of 1</b>\n" in your test.txt file.

The odd thing about your code (aside from the lack of decent indentation) is what happens when these conditions are met:

if ($a eq $location) { if($b eq $obj_name) { $c=$page; $_=~s/<\?--([^-]*)-([^-]*)-->(.*?)<\/\?--([^-]*)-([^-]*)-->/ +/sg; } }
This erases all of the strings from $_ that are running the while() loop; as a result, once these conditions are met, there will be no more iterations of the while() loop (it has the same effect as saying "last;"). So your output file will only contain whatever has been assigned to $list up to this point (including the block of text that matched those two conditions).

Was this intentional? If so, it would make more sense to do it this way:

while(/<\?--([^-]*)-([^-]*)-->(.*?)<\/\?--([^-]*)-([^-]*)-->/sg) { ($a,$b,$c,$d,$e) = ($1,$2,$3,$4,$5); if ($a eq $location and $b eq $obj_name) { $c = $page; $page = undef; } $list=$list. "<?--$a-$b-->$c</?--$d-$e-->\n"; last if ( not defined( $page )); }
This will do the same thing as your original code.

Apart from that, it doesn't seem as though you're doing anything bad to the tags that do get written to the output.

If your intention is to keep the entire file intact, and just replace the one piece of text contained within a particular tag, get rid of the "$_ =~ s/...//sg;"

If you want to remove the whole tag block (open-tag, close-tag and enclosed text) when you spot a certain tag name, replace the "$c=$page; $_=~s/...//sg;" with "next;"