You might like this:

use strict; use warnings; use HTML::TreeBuilder; my $html; $html .= $_ while <DATA>; my $Tree = HTML::TreeBuilder->new (); $Tree->parse ($html); $Tree->eof (); my %Words; ++$Words{$_} foreach (split (" ", $Tree->as_text ())); my @WordPos; my $Key; foreach $Key (keys %Words) { pos ($html) = 0; while ($html =~ />[^<]*?(\b$Key\b).*?[<\$]/gis) { push @WordPos, [$Key, $-[1]]; } } print join "\n", map {ref $_ ? join ' starts at ', @$_ : $_} @WordPos; __DATA__ <HTML> <body poop=smelly> <img src="PleaseDon'tMuntMe.gif"/> <p> This is my text. I <b>hope</b> you like it! img src, please don't munt me. <table> <tr> <td> Would you like to see my Monkey? </td> </tr> </table> </body> oh and this too!
don't starts at 126 you starts at 97 you starts at 182 img starts at 110 hope starts at 88 my starts at 73 my starts at 198 is starts at 70 This starts at 65 see starts at 194 munt starts at 132 like starts at 101 like starts at 186 to starts at 191 Monkey? starts at 201 this starts at 65 Would starts at 176 please starts at 119 I starts at 83

Perl is Huffman encoded by design.

In reply to Re^3: regex for search and replace of words in HTML by GrandFather
in thread regex for search and replace of words in HTML by jqcoffey

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.