if (length $word > 45) { my $forty_sixth = substr($word, 45, 1); $word = substr($word, 0, 45); $word =~ s/\s*\w*\z// if $forty_sixth =~ /\w/; }