Functors implementation in Perl