Perl code that breaks a line after fixed number of columns
I am not sure it can be optimized in a sense of better performance. It could be streamlined though. The initial test for length($line) &lt;= $LINE_LENGTH is just redundant. Compare:

    while (length ($line) &gt; LINE_LENGTH) {
        $prefix = substr($line, 0, $LINE_LENGTH - 1 );
        $line = substr($line, $LINE_LENGTH - 1);
        printf("%s\n", $prefix);
    }
    printf("%s",$line );


PS: I am not familiar with perl enough. If there is a split at position function, you may use it instead of calling substr twice.