Moin, moin!
Wie wäre es mit dieser Lösung?
sub trim {
my $string = shift;
my @sentence = split(/\s+/,$string);
my $word_length_max = 40;
foreach $word (@sentence)
{
$sentence[$j]=~s/(.{$word_length_max})/$1-/sg;
}
$string = join(" ",@sentence);
return $string;
}
Alles klar?
Norbert