for my $i(0..scalar(@{$data[0]})-1){ my $max = find_longest(map{$_->[$i]}@data); $format .= '%-'.$max.'s '; }