#!/usr/bin/perl use strict; my $width = 80; my $len = 0; my $columns = 5; my $column_stop = int($width/$columns); while(<>){ my $line_length = 0; my @words = split(/ +/, $_); foreach my $word (@words){ my $col = 0; for(my $i=1;$i<=$columns;$i++){ if($i*$column_stop > $line_length + length($word)){ $col = $i; } } if($col == 0){ print "\n"; $line_length = 0; } while(length($word) < $column_stop){ $word .= " "; } $line_length += length($word); print $word; } }