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