$errmsg =~ /^ # start at beginning of string (?: # look at first group \[ # an opening square bracket [\w ]+ # followed by one or more word char/spaces ] # followed by a closing square bracket ) # end first group {3} # capture should be 1 time ( # begin second capture .+ # match anything else 1 or more times ) # close second capture