in reply to addition in regular expressions

Use the /e-Modifier:
s{total of (.*?) and (.*?)\n}{'total is ' . ($1+$2) . '\n!'}eg;