# This code is not tested. Sorry. sub _find_var_loop { my($hash,$prefix,$var) = @_; my @results; # go through each entry in our symbol table hash... while (my($name,$glob) = each %$hash ) { if ($var eq \${ $glob }) { push @results, $perfix.$var; # add $var to our list } # is it another symbol table hash? # (ignore main:: to not infinite loop) if ($name =~ /::\z/ and $name ne 'main::') { # recurse... push @results, _find_var_loop(\%{ $glob }, $prefix.$name, $var); } } return @results; } sub find_var { # usage: my @names = find_var($var); return _find_var_loop(\%main::, "", \$_[0]) }