http://www.perlmonks.org?node_id=738837


in reply to How to call sub defined in a variable?

Another way to do it. Put your code references in a hash, otherwise known as a dispatch table:

# Pick a more descriptive name for this hash, depending on your need my %subroutines = ( test => \&test, another_test => \&another_test, third_test => \&third_test, ); for (qw(test another_test third_test)) { $subroutines{$_}->(); }

This lets you define exactly which routines you can call using this method, rather than opening up everything and anything in the main namespace.