in reply to Re^2: Breaking String
in thread Breaking String

Using Text::Wrap module is the better way. Here is the solution without using that module.
#! /usr/bin/perl my @arr = split("", $ARGV[0]); my ($i, $len) = 0; my $newlines=''; my $maxlen = 60; while ($i <= length($ARGV[0])) { $str1 = $str1 . $arr[$i]; my $len = length($str1); if ($len == $maxlen) { if ($str1 =~ /\S+$/) { $str1 =~ s/\s+(\S+)$//; $newlines .= $str1 . "\n"; $i = length($newlines)-2; $str1= "";$len=0 } else { $newlines .= $str1 . "\n"; $str1 = "";$len=0 } } $i++; } print "$newlines\n";