use strict;
my $str = 'car apple view crashed
car doormat elephant crashed
car humus zap crashed
car banana crashed
car crashedddd
^ the above shouldn\'t matchd';
my $regex = qr/car (zap(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|yes(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|xerox(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|with(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|view(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|under(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|this(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|sort(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|rest(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|quick|(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|orange(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|nope|(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|letter(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|kayak(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|joseph(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|indiana(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|humus(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|gelatin(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|frankfurter(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|elephant(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|doormat(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|carrot(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|banana(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?|apple(?: zap| yes| xerox| with| view| under| this| sort| rest| quick| pie| orange| nope| meal| letter| kayak| joseph| indiana| humus| gelatin| frankfurter| elephant| doormat| carrot| banana| apple)?) crashed/p;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html