my $i = 1; foreach my $word(@words){ $word = ' ' x (10 - length($word)).$word; $i = sprintf("%5d",$i); print $i," ",$word; print $i % 3 == 0 ? "\n" : "\t"; $i++; }