my @colLength; sub calcMaxColumn { # $i will hold index locations of column lengths in the array @colLengths. my $i; # Loop through the array @AoA. And if the length of the current column is greater then the length of the # same column in the previous row then set the greater number equal to that location in @colLength. for (my $x = 0; $x <= $#AoA; $x++) { $i = 0; for (my $y = 0; $y <= 11; $y++) { if ($colLengths[$i] < length($AoA[$x][$y])) { $colLengths[$i] = length($AoA[$x][$y]); } $i++; } } }