in reply to Subroutines in a regex?

This is what the 'e' option is designed for:
s/SUM(\d*)/sum($1)/ge

Originally posted as a Categorized Answer.