$string1 =~ m/ (?:one=(.*?),)? .*? (?:two=(.*?),)? .*? (?:three=(.*?),)? .*? (?:four=(.*?),)? .*? (?:five=(.*?),)? /x;