in reply to printing 20 characters in a line.
$str=~s/((?:\d+ ){20})/$1\n/g; print OUT "$str\n"; [download]
or, to avoid modifying $str and be rid of trailing spaces
my $tmp = $str; $tmp =~ s/((?:\s*\d+){20})/$1\n/g; print OUT "$tmp\n"; [download]
update: get rid of leading spaces
my $tmp = $str; $tmp =~ s/\s*((?:\s*\d+){20})/$1\n/g; print OUT "$tmp\n"; [download]