Let's talk you through this. First of all, you want to substitute newlines for spaces:
s/\s/\n/g;
But you want the space to be preceded by at least 10 non-newlines:
s/(?<=[^\n]{10})\s/\n/g;
But this doesn't work, because the newlines we put in aren't found by the lookbehind, so we're going to have to consume and replace characters instead of using lookbehind:
s/([^\n]{10})\s/$1\n/g;
I'm still using [^\n] because I assume that if the string already has embedded newlines, you want the counter to reset.

Ok, bonus round: there is a way to do it with lookbehind, but it's ugly. We use \G to indicate where the last match left off. We want there to be at least 10 non-newlines between any new match and the old one. So:

s/(?<=(?:(?<!\G)[^\n]){10})\s/\n/g;
The lookbehind is "10 non-newlines, and be sure that none of them is immediately preceded by the previous match".

Update: Ok, re-reading the original question, we don't want to SUBSTITUTE for spaces, we want the newline to be inserted AFTER a space, and the space is (at least) the 10th character, meaning it's preceded by 9 chars. Thus:

s/([^\n]{9}\s)/$1\n/g;
(thanks to ambrus)

The PerlMonk tr/// Advocate

In reply to Re: Counting characters in a string by Roy Johnson
in thread Counting characters in a string by TASdvlper

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.