in reply to Finding the largest word in a string help!

(my $break2 = $str2)=~ s/(length($str2)>30)/$1\n/mg;

You can't just use any code inside a regular expression and expect it to work.

I'd approach the problem like this:

sub break_word { my $str = shift; # break up $str into separate words, # and return the result ... } # search for all words longer than 30 characters: s/(\S{31,})/ break_word($1) /eg;