in reply to Split String after nth occurrence of a charater

You specification is rather vague. Using the word split is likely to make a Perl user think you want to split your string into possibly more than two parts. The following does that trick:

my $string = join ' ', 1 .. 30; my @parts = $string =~ /((?:\S*\s?){1,11})/g; pop @parts; print ">$_<\n" for @parts;

Prints:

>1 2 3 4 5 6 7 8 9 10 11 < >12 13 14 15 16 17 18 19 20 21 22 < >23 24 25 26 27 28 29 30<
True laziness is hard work

Replies are listed 'Best First'.
Re^2: Split String after nth occurrence of a charater
by Amiru (Initiate) on Nov 08, 2011 at 12:18 UTC
    ok.. didn't think of this before, as I was going to keep splitting in 11th space of the right string, but this does it. Thank you