my @strings = ('Hallo K', 'Hallo Karl'); for (@strings) { print "$_ : ", teste_string($_), "\n"; } sub teste_string { my ($string) = @_; my $ok = 1; for (split /\s+/, $string) { $ok = 0 unless /\b([a-zA-Z0-9]{2,50})\b/; } return $ok; }