# match everything at once @everything = /^\s*(\w+)\s*=\s*(\w+)(\s*,\s*\w+)?(\s*,\s*\w+)?(\s*,\s*\w+)?$/ #### # match the required part /^\s*(\w+)\s*=\s*(\w+)/gc; ($keyword, $value) = ($1,$2); # match the optional part @optional = /\G\s*,\s*(\w+)/g;