my %handler = ( hello => sub() { print "hello world\n" }, ); my ($ok,$err); my @handlers = keys %handler; my $cfg_str = 'hello();'; { no strict 'refs'; # We don't want to introduce another scope, as that will # negate the effect of the local: NEXT: { my $n = shift @handlers; local *{$n} = $handler{ $n }; redo NEXT if @handlers; } $ok = eval $cfg_str; $err = $@; } warn $err if $err; __END__ Undefined subroutine &main::hello called at (eval 1) line 1.