#!/usr/bin/perl use strict; use warnings; our $AUTOLOAD; our $hashref = { 'a' => { 'b' => { 'c' => 'this is c', 'd' => 'this is d' } } }; print "a_b_c() = ".a_b_c()."\n"; print "a_b_d() = ".a_b_d()."\n"; exit(0); sub AUTOLOAD { my ($package,$ref_name) = split /::/, $AUTOLOAD; my $ref = '$hashref'. join '', map { "->{$_}" } grep /^\w+$/, split /_/, $ref_name; return eval $ref; } # output for above is: a_b_c() = this is c a_b_d() = this is d