in reply to how would you detect a math expression

In Parse::RecDescent Tutorial, Jeffrey Goff builds a parser that can handle simple expressions like 3 + 5. The article may give you some ideas on how Google calculator works its magic.

HTH,

planetscape