# your data my @vocabulary = qw(a abc abcd abd bc); my $sentence = 'abdaabc'; # regex for words my $re = join '|', @vocabulary; # does it match in *any* way my $success = $sentence =~ /^(?:$re)*$/; # show result print $success || 0; #### 1 #### use re 'debug';