in reply to Subroutines in a regex?

use
s/SUM(\d*)/sum($1)/eg
this will execute the subroutine.