$text=~s{^ # starting at the beginning of the string (.{1,50}) # capture up to 50 characters \s # followed by a space } {$1\n}x; # and replace it with what you captured followed by a newline