in reply to Subroutines in a regex?
s/SUM(\d*)/sum($1)/ge [download]
Originally posted as a Categorized Answer.