qr/^ # Anchors to the beginning of the line -- # I think this may be unnecessary, but # it's not a biggie. foobar # Must have 'foobar' ( # First group .. a? # zero or one 'a' b? # zero or one 'b' c? # zero or one 'c' ) # .. end of first group (is this missing # a '?' to show it's optional?) (?: # Start of a non-capturing group .. X # Must have an 'X' (?=.) # Must have a character (lookahead assertion) ( # Second group .. a? # zero or one 'a' b? # zero or one 'b' c? # zero or one 'c' ) # .. end of second group )? # .. end of non-capturing group, shows group # is optional. $ # Anchors end of line. Same comment as for # beginning anchor.