#example 1 $content =~ s/(.{1,$width}) /$1
/g; print $content; #### #example 2 $content =~ s/(.{1,$width}) |([^ ]{$width})/$1$2
/g; print $content;