my $n = 30; print weave([map{$_%3?' ':"\n"}0..$n-1],[1..$n]); sub weave { my @t; { @$_ ? push @t, shift @$_ : return @t for @_; redo; } }