... $sth->execute; my $all = $sth->fetchall_arrayref; my @max = (0) x 3; foreach my $row (@$all) { for (my $i = 0; $i < @$row; $i++) { $max[$i] = length $$row[$i] if length $$row[$i] > $max[$i]; } }