in reply to How to split a string based on the length of a sequence of characters within the string

      ... 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!