Yes, I know it's not as idiomatic as it could be, but....
sub string-split($str, +@pos) {
my ($str-a, $str-b);
my ($r, $idx) = ($str, 0);
gather while @pos || $str-a {
unless +@pos {
take $r;
last;
}
my $a = @pos.shift - $idx if +@pos;
$str-a = $r.substr(0, $a);
$str-b = $r.substr($a, *);
take $str-a;
($r, $idx) = ($str-b, $a);
}
}
"aaabbcccc".&string-split(3, 5).say
Ah!
$str-b
is uesless, so...