ChemBoy didn't mention this detail, but if you compare his version of the regex against your original, you'll notice another difference, in addition to the use of "e". He used the concatenation operator "." to join $1, the output of the function and $3.
In order for the "e" qualifier to do a proper job, the entire rhs (replacement portion) of the regex needs to be an executable perl statement -- not just a string with an embedded subroutine call.
Comment on Re: Executing a function within a regex