I don't fully understand your requirements (no example data, no expected output), but it seems as if you might want to insert a newline at every place in a long line where the next number and comma would cause the line to exceed n columns. Maybe something like this (needs Perl 5.10+ for \K regex operator, but this can easily be worked around):
Try various values of $max_cols and see how it looks. See also Text::Wrap.c:\@Work\Perl\monks>perl -wMstrict -le "use 5.010; ;; my $s = '1,12,123,1234,12345,123456,1234567,12345678,123456789,1234567890'; $s x= 11; ;; my $max_cols = 29; my $max = $max_cols - 1; ;; $s =~ s{ \G .{1,$max} , \K } {\n}xmsg; print ' 1 2 3 4'; print '1234567890123456789012345678901234567890'; print $s; " 1 2 3 4 1234567890123456789012345678901234567890 1,12,123,1234,12345,123456, 1234567,12345678,123456789, 12345678901,12,123,1234, 12345,123456,1234567, 12345678,123456789, 12345678901,12,123,1234, 12345,123456,1234567, 12345678,123456789, 12345678901,12,123,1234, 12345,123456,1234567, 12345678,123456789, 12345678901,12,123,1234, 12345,123456,1234567, 12345678,123456789, 12345678901,12,123,1234, 12345,123456,1234567, 12345678,123456789, 12345678901,12,123,1234, 12345,123456,1234567, 12345678,123456789, 12345678901,12,123,1234, 12345,123456,1234567, 12345678,123456789, 12345678901,12,123,1234, 12345,123456,1234567, 12345678,123456789, 12345678901,12,123,1234, 12345,123456,1234567, 12345678,123456789, 12345678901,12,123,1234, 12345,123456,1234567, 12345678,123456789, 1234567890
Give a man a fish: <%-{-{-{-<
In reply to Re: Counting characters without a space
by AnomalousMonk
in thread Counting characters without a space
by htmanning
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |