use warnings; use strict; use Data::Dump; my $re = qr{ \A \s* RepeatingGroup \s* = \s* (? \b[^\ \t]+\b ) \s* ( , \s* (?: (? \bFlatten\b ) | (? \b(?:in|out)\b ) ) \s* ){1,2} \z }msx; dd $_, /$re/ ? \%+ : "FAIL" while ; __DATA__ RepeatingGroup = Waiver, Flatten, out RepeatingGroup = Waiver, out RepeatingGroup = Waiver, out, Flatten RepeatingGroup = Waiver , in RepeatingGroup = Waiver , Flatten