Goal for regex, span 80 or fewer characters, and end on a non space. It should be followed by either a space or end of string, and then we should gobble any following spaces so that the following line starts on a character. A web provided description can be found here.
while (<DATA>) {
chomp(my $line = $_);
print "$_\n" for $line =~ /(.{1,80})(?<=\S)(?=\s|$)\s*/g;
}
__DATA__
So-called smartguns have been in the works for years but haven't gotten much traction.
Can also just rely on cpan Text::Wrap