#! perl -slw use strict; my $re = join'', map{ "(?=^.*$_)" } qw[ scan print rinse repeat ]; my $re2 = join'', map{ "(?=^.*($_))?" } qw[ scan print rinse repeat ]; chomp( my @tests = ); print "Just test"; for( @tests ){ printf "$_: %s\n", $_ =~ $re ? 'matched' : 'no match'; } print "\nTest and what"; for( @tests ){ my @matched = grep defined, $_ =~ $re2; printf "$_: %s\n", @matched ? "matched: [@matched]" : 'no match'; } __DATA__ scan and print and rinse and repeat print and scan and rinse and repeat print and scan and rinse print fred #### C:\test>junk44 Just test scan and print and rinse and repeat: matched print and scan and rinse and repeat: matched print and scan and rinse: no match print: no match fred: no match Test and what scan and print and rinse and repeat: matched: [scan print rinse repeat] print and scan and rinse and repeat: matched: [scan print rinse repeat] print and scan and rinse: matched: [scan print rinse] print: matched: [print] fred: no match