use List::Util qw( reduce ); sub symref { local $_ = shift; reduce { $a && exists $a->{ "${b}::" } ? $a->{ "${b}::" } : () } \%main::, split /::/; }