#!/usr/bin/perl -w use strict; my $string = 'I'm trying to have a word wrapping using a regex in Perl. What I would like is about every 50 characters or so to check for the next white-space occurrence and replace that space with a newline, and then do this for the whole string. I'd like to avoid looping one character at a time or using substr or placing the value into an array if possible. The code sample I have works, I'd like someone option and suggestion is there a better way or better regular expression to accomplish this.'; $string =~ s/(.{1,50}\S|\S+)\s+/$1\n/mg; print "$string\n"; exit;