in reply to Counting characters in a string

my $str = "this is just a test\nthis is another test\nthis is yet anot +her test\n"; $str =~ s/(.{5})/$1\n/sg; print $str;

But that actually outputs:

---start output--- this is ju st a test this is an other test this is y et an other test ---end output---

Which isn't what your example showed, but is what you asked for.