use strict; my @array = qw/one two three four five six seven eight nine ten/; my $cols = 3; my $max = 0; $max < length($_) and $max = length($_) for @array; my $output = ""; my @copy = @array; while (@copy) { $output .= join(" ", map sprintf("%-${max}s", $_), splice @copy, 0, 3)."\n"; } print $output;