sub doubleStack { my $count = pop; my @out; while (@_){push @out, [splice @_,0,$count];} return @out; } #### doubleStack(qw(a b c e 1 2 3 4 5 3 f),3) returns: $VAR1 = [ [ 'a', 'b', 'c' ], [ 'e', '1', '2' ], [ '3', '4', '5' ], [ '3', 'f'] ];