I'd use a module to strip the HTML. Here's a quick try:
use HTML::TokeParser::Simple; my $doc = qq(story on GettingIt about <a href="http://ss.gettingit.com +/cgi-bin/gx.cgi/AppLogic+FTContentServer?GXHC_gx_session_id_FutureTen +seContentServer=7f12a816fa48a5b9&pagename=FutureTense/Demos/GI/Templa +tes/Article_View&parm1=A1545-1999Oct12&topframe=true">hacking polls</ +a>. Contrary to what the article says, Time is <b>not</b> checking fo +r multiple votes on <a href="javascript:document.timedigital.submit() +;">their poll</a>. And I'm happy to report that despite the fact that + my cheater scripts aren't running, I'm still beating Bill Gates.); my $doc2; my $total = 0; my $p = HTML::TokeParser::Simple->new( \$doc ); while ( my $token = $p->get_token ) { if ($token->is_text) { if (length($token->return_text) + $total <= 200) { $doc2 .= $token->return_text; $total += length($token->return_text); } else { for (split / /, $token->return_text) { if ($total + length($_) <= 200) { $doc2 .= $_ . ' '; $total += length($_) + 1; } else { last; } } chop($doc2) if $doc2 =~ /\s$/; } } else { $doc2 .= $token->as_is; } } print $doc2;
Prints
story on GettingIt about <a href="http://ss.gettingit.com/cgi-bin/gx.c +gi/AppLogi c+FTContentServer?GXHC_gx_session_id_FutureTenseContentServer=7f12a816 +fa48a5b9&p agename=FutureTense/Demos/GI/Templates/Article_View&parm1=A1545-1999Oc +t12&topfra me=true">hacking polls</a>. Contrary to what the article says, Time is + <b>not</b > checking for multiple votes on <a href="javascript:document.timedigi +tal.submit ();">their poll</a>. And I'm happy to report that despite the fact tha +t my cheat er scripts
HTH

Update: changed < limit to <= limit

Update: strike that last one -- misunderstood the question. here's try #2! :) fixes welcome!

--
"To err is human, but to really foul things up you need a computer." --Paul Ehrlich

In reply to Re: Extracting a substring of N chars ignoring embedded HTML by LTjake
in thread Extracting a substring of N chars ignoring embedded HTML by FamousLongAgo

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.