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