sub split_list { use integer; my ( $list_ref, $qty, $pad ) = @_; return unless ref $list_ref eq 'ARRAY'; my @return; if ( !( @$list_ref % $qty ) || @_ == 2 ) { push @{ $return[$_ % $qty] }, $list_ref->[$_] for 0 .. $#$list_ref; } else { my $padded = $qty - @$list_ref % $qty; push @{ $list_ref }, ($pad) x $padded; push @{ $return[$_ % $qty] }, $list_ref->[$_] for 0 .. $#$list_ref; pop @$list_ref for 1 .. $padded; } return @return if wantarray; return \@return; }