This might get closer to the requirement assuming that any embedded angle brackets are escaped.

Updated: Added a case to deal with long block of unbroken word chars.

Updated again.

#! perl -slw use strict; use Inline::Files; select OUTPUT; while( <DATA> ) { s[ ( (?:<[^>]+>) | (?:[^<]{9,18}(?=\b\W)) | [^<]{18} ) ][$1 \n]xg; print; } __DATA__ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxx http://news.bbc.co.uk/1/shared/spl/hi/pop_ups/05/business_detroit_moto +r_show/html/1.stm/1.stm this is the <a href="http://news.bbc.co.uk/1/shared/spl/hi/pop_ups/05/ +business_detroit_motor_show/html/1.stm/1.stm">link</a> I was referrin +g to for( 1 .. 20 ){ $bar = $bop[ 1 ]; print "$bar/$baz,$foo[$baz]" } for(1..20){$bar=$bop[1];print"$bar/$baz,$foo[$baz]"} for(1..20)%7B%24bar%3D%24bop%5B1%5D%3Bprint%22%24bar%2F%20%24baz%2C%24 +foo%5B%24baz%5D%22%7D __OUTPUT__ xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxx http://news.bbc.co .uk/1/shared/spl /hi/pop_ups/05 /business_detroit_ motor_show/html/1 .stm/1.stm this is the <a href="http://news.bbc.co.uk/1/shared/spl/hi/pop_ups/05/business_de +troit_motor_show/html/1.stm/1.stm"> link</a> I was referring to for( 1 .. 20 ){ $bar = $bop[ 1 ]; print "$bar /$baz,$foo[$baz ]" } for(1..20){$bar =$bop[1];print "$bar/$baz,$foo [$baz]"} for(1..20)%7B %24bar%3D%24bop %5B1%5D%3Bprint%22 %24bar%2F%20%24baz %2C%24foo%5B%24baz %5D%22%7D

This version

  • avoids inserting an extra space where the text breaks at a space.
  • tries to keep short quoted strings unbroken
    #! perl -slw use strict; use Inline::Files; select OUTPUT; while( <DATA> ) { s[ ( (?: < [^>]+ > ) | (?: ( ["'] ) (?: (?!\2). ){1,18} \2 ) #"' | (?: [^<"'6]{9,18} (?=\b\W) ) #"' | [^<'"]{18} #"' ) \s? ][$1 \n]xg; print; } __DATA__ a line with "some quoted text" less than 18 chars in length and "some +quoted text more that 18 chars" a line with 'some quoted text' less than 18 chars in length and 'some +quoted text more that 18 chars' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxx http://news.bbc.co.uk/1/shared/spl/hi/pop_ups/05/business_detroit_moto +r_show/html/1.stm/1.stm this is the <a href="http://news.bbc.co.uk/1/shared/spl/hi/pop_ups/05/ +business_detroit_motor_show/html/1.stm/1.stm">link</a> I was referrin +g to for( 1 .. 20 ){ $bar = $bop[ 1 ]; print "$bar/$baz,$foo[$baz]" } for(1..20){$bar=$bop[1];print"$bar/$baz,$foo[$baz]"} for(1..20)%7B%24bar%3D%24bop%5B1%5D%3Bprint%22%24bar%2F%20%24baz%2C%24 +foo%5B%24baz%5D%22%7D __OUTPUT__ a line with "some quoted text" less than 18 chars in length and "some quoted text more that 18 chars " a line with 'some quoted text' less than 18 chars in length and 'some quoted text more that 18 chars ' xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxx http://news.bbc.co .uk/1/shared/spl /hi/pop_ups/05 /business_detroit_ motor_show/html/1 .stm/1.stm this is the <a href="http://news.bbc.co.uk/1/shared/spl/hi/pop_ups/05/business_det +roit_motor_show/html/1.stm/1.stm"> link</a> I was referring to for( 1 .. 20 ){ $bar = $bop[ 1 ]; print "$bar/$baz,$foo [$baz]" } for(1..20){$bar =$bop[1];print "$bar/$baz,$foo [$baz]"} for(1..20)%7B %24bar%3D%24bop %5B1%5D%3Bprint%22 %24bar%2F%20%24baz %2C%24foo%5B%24baz %5D%22%7D

    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.

    In reply to Re: A call to keyboards: Better chatterbox wrapping by BrowserUk
    in thread A call to keyboards: Better chatterbox wrapping by demerphq

    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.