foreach my $w (@words) { my $lw = length $w; if($cols_left > $lw) { $para .= ' ' if $cols_left < $self->columns; $para .= $w; $cols_left -= $lw; } else { $para .= "\n$w"; $cols_left = $self->columns - $lw; } }