#! /opt/perl/bin/perl use strict; use warnings; my $text = "Hello, I am a perl/mysql programmer, but am self taught so I do not know all the awesome features Perl has, however, I am ok at it though, I guess."; sub split_at { my ( $text, $len ) = @_; my @result; my @parts = split /[ ]/, $text; my $short = shift @parts; while ( @parts ) { if ( length($short) + length($parts[0]) < $len ) { $short = join( ' ', $short, shift @parts ); } else { push @result, $short; $short = shift @parts; } } push @result, $short; return @result; } { local $, = local $\ = $/; print split_at( $text, 100 ); # beware print split_at( 'a'x110, 100 ); }