Yuck. Below is a script that i used recently to script out a lot of word-generated junk .. caveat emptor--it was a quick & dirty solution for my specific files. But some of the regex's maybe of some use. Note that it gets rid of everything inbetween
<!...> tags, and also pretty much strips also style junk with
mso in it.
Usage: cleanWord.pl infile > outfile
#!/usr/bin/perl -p0777
s#<!--.*?-->##sg;
s#<!\[if .*?\]>(.*?(?!<!).*?)<!\[endif\](--)?>##sg;
s#<o:p></o:p>##sg;
s#<span\s+style='(?:(?:mso-bidi-)?font-size:\d+\.\d+pt;\s*)?font-famil
+y:Arial'>([^<]*)</span>#$1#sg;
s#<ol start=1 type=1>#<ol>#sg;
s#<li[^>]+>#<li>#sg;
s#<span\s+style='(?:(?:mso-bidi-)?font-size:\d+\.\d+pt;\s*)?font-famil
+y:Arial'>#<span>#sg;
s#<span\s+style="mso-spacerun:\s*yes">#<span>#sg;
s#<b style='mso-bidi-font-weight:\s*normal'>#<b>#sg;
s#<p[^>]*?>#<p>#sg;
s#<span[^>]*?>(.*?(?!span).*?)</span>#$1#sg;
s#<span>(.*?(?!span).*?)</span>#$1#sg;
# s#(<img.*?src=")[^>]+/[^>]+\.([^\.>]+?)(">)#sprintf("%simage%04d.%s%
+s",$1,++$N,$2,$3)#sge;
s#(<img.*?\s+)id="\S+"([^>]*?>)#$1$2#sg;
s#class=section#class="Section"#sg;
As for a more generic approach, I haven't used one, but a quick cpan search or
HTML yields
HTML::Scrubber and
HTML::Sanitizer which (at a 2-s glance) look promising.