in reply to Tricky regexp...

Here is a very generic example of HTML::Parser applied to your problem. replace $html with your HTML, and s///g with your pattern replacement and you should be on your way.
#!/usr/bin/perl -w use strict; use HTML::Parser; my $html = "<HTML> from a file or wherever</HTML>"; my @parsed; my $p = HTML::Parser->new(api_version=> 3, handlers=> {default=>[\@parsed,"event,text"] +}, ); $p->parse($html); for (@parsed) { $_->[1] =~ s///g if $_->[0] eq 'text'; }