use List::Util qw( max ); use List::MoreUtils qw( mesh ); # Find the length of the longest list. my $longest = max map { scalar @{ $_ } } @{ $foo }; # Pad every array to equal length using empty strings. push @{ $_ }, ( q{} ) x ( $longest - scalar @{ $_ } ) for @{ $foo }; # Since 'mesh' takes a list of arrays, using a prototype, # I use '&mesh' to avoid the prototype. my @meshed = &mesh( @{ $foo } ); # Alternate way to do the same thing #my @meshed = eval "mesh " . join q{,}, # map { "\@{ \$foo->[ $_ ] }" } 0 .. $#{ $foo }; # Pull out the individual rows. my $bar = []; push @{ $bar }, [ splice @meshed, 0, $longest ] while @meshed;