in reply to Regular expression for C statement

Regular expressions are not the right tool for the job. You want a proper parser. Parse::RecDescent is probably sophisticated enough.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'