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; #### ---start output--- this is ju st a test this is an other test this is y et an other test ---end output---