if ($string = /... ( ... ) .../) { # overall match if ($1 =~ /foo/) { # and $1 contains foo ... } elsif ($1 =~ /bar/) { # nope? how about bar ... } }