So you need to hold a mapping table for the OIDs <-> Type, and a way to define how the inner thing is embedded.
The code todo that is already in C::ASN1, you do it like
$asn->registeroid('2.5.29.17' => $asn->find('SubjectAltName'));
Take a look in t/14any.t in the distribution
I really must write some documentation for this.
I've written a number of modules which use 'ANY DEFINED', including one to parse X509 certificates (it does Extensions in a second pass, though). Code is available from
http://cvs.dcs.ed.ac.uk/cgi-bin/cvsweb.cgi/perl-Crypt-ASN1/
if folk are interested.
Cheers,
Simon.