rework perl extensions to correctly use OUTPUT/RETVAL