>perl -wMstrict -le "my @strings = qw(nowknow knownow know now no); ;; my $pattern1 = qr{ now }xms; my $pattern2 = qr{ know }xms; ;; my $regex1 = qr{ (?= \A .*? $pattern1) (?= \A .*? $pattern2) }xms; my $regex2 = qr{ $pattern1 $pattern2 | $pattern2 $pattern1 }xms; ;; for my $regex ($regex1, $regex2) { print qq{for regex $regex}; for my $string (@strings) { print qq{ '$string' has }, $string =~ $regex ? 'a' : 'NO', ' match'; } } " for regex (?msx-i: (?= \A .*? (?msx-i: now )) (?= \A .*? (?msx-i: know )) ) 'nowknow' has a match 'knownow' has a match 'know' has a match 'now' has NO match 'no' has NO match for regex (?msx-i: (?msx-i: now ) (?msx-i: know ) | (?msx-i: know ) (?msx-i: now ) ) 'nowknow' has a match 'knownow' has a match 'know' has NO match 'now' has NO match 'no' has NO match