c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'xx foo yy bar zz baz'; ;; if (my ($c1, $c2, $c3) = $s =~ m{ \A (?! .* zot) (?= .* (bar)) (?= .* (baz)) (?= .* (foo)) }xms ) { print qq{c1 '$c1' c2 '$c2' c3 '$c3'}; } " c1 'bar' c2 'baz' c3 'foo' #### c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'xx foo yy bar zz baz'; ;; my $match = my ($c1, $c2, $c3) = $s =~ m{ \A (?! .* zot) (?= .* (bar)) (?= .* (baz)) (?= .* (foo)) }xms; ;; if ($match) { print qq{c1 '$c1' c2 '$c2' c3 '$c3'}; } else { print 'no match'; } " c1 'bar' c2 'baz' c3 'foo'