in reply to A useful use of goto

There are a few more solutions that you could have used.

First and foremost, use a Safe. For example:

use Safe; my $config = Safe->new; *{ $config->varglob($_) } = $handler{$_} for keys %handler; $ok = $config->reval( $cfg_str ); # Or: $ok = $config->rdo( $config_source ); $err = $@;
When you are done, you can simply throw away the Safe object, and everything is totally cleaned up.

Secondly, (if using regular string eval, and not a Safe) you could have added the following to your $cfg_str:

join ";\n", map "local *$_ = \$handler{$_}", keys %handler;
That would have cause the local to be undone the moment the string eval finished running.

Thirdly, you could have used recursion:

local *handler_localizer = sub { if( my $name = each %handler ) { no strict 'refs'; local *{$name} = $handler{$name}; handler_localizer(); } else { $ok = eval $cfg_str; $err = $@; } };
But this is silly, when a Safe is so much simpler.