my @vocabulary = qw(a abc abcd abd bc); my $sentence = 'abdaabc'; #### my $pattern = join '|', @vocabulary; $sentence =~ /^($pattern)+$/; print $1; my @list1; $sentence =~ /^(($pattern)(?{push @list1, $^N}))+$/; print (join ",", @list1), "\n"; use Regexp::DeferredExecution; my @list2; $sentence =~ /^(($pattern)(?{push @list2, $^N}))+$/; print (join ",", @list2), "\n"