in reply to Counting characters in a string

my $c_per_line = 5; print "$1\n" while ($string =~ /(.{0,$c_per_line})/sg);
Update: added "0," so that the match would include the final few characters.

The PerlMonk tr/// Advocate