$_ = "a b=c"; /(a)(.*)(?:b=(\w))?/; printf "\$2 is [%s]\n", defined $2 ? $2 : "undefined"; printf "\$3 is [%s]\n", defined $3 ? $3 : "undefined";