Well, your code could be optimized, but as a pure perl code, it will be very hard to give performance boost of 3 times faster than it was. If it is the execution speed you are looking for, why not try the
Inline::C module and write your function in C? It will certainly give you the performance boost you are looking for.