Ordinarily I'd say this is a job for HTML::TokeParser. What you describe would be very simple to implement using it, and it would be fairly easy to fix if it breaks when MSWord's HTML output changes in some bizarre way in a future edition (extremely likely to happen). There's even a tutorial here about it, which should make it that much easier to figure out.

On the other hand, it seems somewhat churlish to tell you to bring in the whole HTML::Parser suite just for the last 1% of your code... but actually, I'm going to. The reason is this: I could try to write the regex you need (though it would take longer than writing it with TokeParser), but I would probably fail. Several people would then respond with corrections explaining what I had missed, and that I was stupid to try to use a regex instead of TokeParser. And they would be right. Somebody might actually supply a regex that would do what you want, but

The upside is that you may look at TokeParser and realize that it could vastly simplify your script to use it in some other places--this is, after all, what CPAN modules are best at. :-)

You should also look at the base HTML::Parser module, just to see if the model it uses for parsing makes more sense to you--both systems have their advocates.



If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders


In reply to Re: Very specific HTML parsing question by ChemBoy
in thread Very specific HTML parsing question by russmann

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.