You might find perloptree and the B modules helpful, in particular B::Generate
In reply to Re: create a CODE ref from a parse tree? by ig in thread create a CODE ref from a parse tree? by perl5ever