... and just to add another sprig of julep:

C:\>perl -E "my $input='#abcd#ef#ghi#jklmnopqrstuv'; my @chunks = spli +t(/([a-z]{3})/,$input); use Data::Dumper; say Dumper @chunks;" $VAR1 = '#'; $VAR2 = 'abc'; $VAR3 = 'd#ef#'; $VAR4 = 'ghi'; $VAR5 = '#'; $VAR6 = 'jkl'; $VAR7 = ''; $VAR8 = 'mno'; $VAR9 = ''; $VAR10 = 'pqr'; $VAR11 = ''; $VAR12 = 'stu'; $VAR13 = 'v';

Whereas without the capturing parens:

C:\>perl -E "my $input='#abcd#ef#ghi#jklmnopqrstuv'; my @chunks = spli +t(/[a-z]{3}/,$input); use Data::Dumper; say Dumper @chunks;" $VAR1 = '#'; $VAR2 = 'd#ef#'; $VAR3 = '#'; $VAR4 = ''; $VAR5 = ''; $VAR6 = ''; $VAR7 = 'v';

As suggested above, a simple regex might serve you better, and with fewer "gotcha's" ... whereas, while this might be a legitimate approach for certain problem cases, it is most certainly likely to be a HUGE! PITA for some successor_dev).

Afterthought (i.e., UPDATE) re OP's title: You're not trying "to split a string based on character(s) length" (as your title says, because

Rather, you are trying to split a string based on a the length of a sequence of characters within the string (AKA: 'a substring length').


check Ln42!


In reply to Re: How to split a string based on character(s) length by ww
in thread How to split a string based on the length of a sequence of characters within the string by thanos1983

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.