in reply to greedy/nongreedy regex replacement

With a negative lookahead, yes:
$string =~ s/<tr(?:(?!<tr>).)+?NOTWANTED.+?<\/tr>//gsm;
For each char after the opening <tr, it makes sure that it's not the beginning of a closingnested tag.

Caution: Contents may have been coded under pressure.