in reply to storing perl code in database

I'm not a DB programmer, so this may be off base: Does your version/configuration of postgres support PL/Perl?

PL/Perl handles storing Perl functions for you. I believe it shifts execution of the stored Perl functions onto the database's host, so it may not be what you want. It would probably also require a change to the architecture of your application.