Note that this has NOTHING to do with the fact that you use variables to contain the name of another variable.
The reason this doesn't work is because the ${"var_a"} construct actually refers to the package level variable $main::var_a .
Since $var_a declared as a lexical variable, it is a DIFFERENT identifier, and therefore ${"var_a"} is undef.
You can see that if you change my $var_a to our $var_a
our $var_a="a"; my $var_b="b"; $var_c="c"; print ${"var_a"},"\n"; print ${"var_b"},"\n"; print ${"var_c"},"\n";
As others have noted, although there is a good explanation of why what you are trying to do does not work, what you are doing is most likely the wrong approach. You will almost never use this method unless there is a better way; without your problem, itβs not clear what the best way is, but most likely there will be a hash, as TLP says.
source share