sub split_into { my ($n, @from, @to) = @_; while (@from) { push @{$to[$i++]}, shift @from; i %= $n; } @to; } @results = split_into(3, 'a' .. 'z');