Maybe something like this could be adjusted to your needs?

#! perl -slw use strict; our $N ||= 16; my $longstring = do{ local $/; <DATA> }; for my $n ( map{ $_*50 } 4 .. $N ) { my $cutoff1 = 1+rindex $longstring, '<', $n; my $cutoff2 = length $1 if $longstring =~ m[^(.{0,$n}[\.,:;!?])]s; my $cutoff3 = 1+rindex $longstring, ' ', $n; my $cutoff = $cutoff1 > ( $n - 25 ) ? $cutoff1 : $cutoff2 > ( $n - 25 ) ? $cutoff2 : $cutoff3; my $substring = substr $longstring, 0, $cutoff-1; print "\n$n($cutoff)\n'$substring'"; } __DATA__ <p> Welcome to the Perl Monastery. We hope your stay is long and enjoyable. You are probably wondering what PerlMonks is all about. Hopefully this page will answer some of those questions. </p><p> <b>What Perl Monks is:</b><br /> <li>Our attempt to make learning Perl as nonintimidating and easy to use as possible <li>A place for you and others to polish, improve, and showcase your Perl skills <li>A community which allows everyone to grow and learn from each other. </p> <p><b>Areas within the monastery:</b></p> <ul> <p><li><a href="/index.pl?node=Seekers%20of%20Perl%20Wisdom">Seekers o +f Perl Wisdom</a>-The place you can go when you have got a question on how to do something or are unsure why something just isn't working. Then other monks can offer you their wisdom and suggestions. </p>

Output:

P:\test>junk -N=8 200(199) '<p> Welcome to the Perl Monastery. We hope your stay is long and enjoyable. You are probably wondering what PerlMonks is all about. Hopefully this page will answer some of those questions. </p>' 250(236) '<p> Welcome to the Perl Monastery. We hope your stay is long and enjoyable. You are probably wondering what PerlMonks is all about. Hopefully this page will answer some of those questions. </p><p> <b>What Perl Monks is:</b><br /> ' 300(297) '<p> Welcome to the Perl Monastery. We hope your stay is long and enjoyable. You are probably wondering what PerlMonks is all about. Hopefully this page will answer some of those questions. </p><p> <b>What Perl Monks is:</b><br /> <li>Our attempt to make learning Perl as nonintimidating and' 350(345) '<p> Welcome to the Perl Monastery. We hope your stay is long and enjoyable. You are probably wondering what PerlMonks is all about. Hopefully this page will answer some of those questions. </p><p> <b>What Perl Monks is:</b><br /> <li>Our attempt to make learning Perl as nonintimidating and easy to use as possible <li>A place for you and' 400(396) '<p> Welcome to the Perl Monastery. We hope your stay is long and enjoyable. You are probably wondering what PerlMonks is all about. Hopefully this page will answer some of those questions. </p><p> <b>What Perl Monks is:</b><br /> <li>Our attempt to make learning Perl as nonintimidating and easy to use as possible <li>A place for you and others to polish, improve, and showcase your Perl'


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

janitored by ybiC: Balanced <readmore> tags around longish example codeblock


In reply to Re: Find a good starting section of a long text by BrowserUk
in thread Find a good starting section of a long text by johnnywang

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.