$ cat disp_tbl.pl #!/usr/bin/perl use strict; use warnings; use feature ':5.10'; sub foo { say "foobar" } sub bar { say "barbaz" } my %DT = ( foo=>\&foo, bar=>\&bar, quit=>sub { die "END!"; } ); say "Commands are foo, bar and quit\n"; while (<>) { chomp; if (exists $DT{$_}) { $DT{$_}(); } } $ perl disp_tbl.pl Commands are foo, bar and quit foo foobar bar barbaz quit END! at disp_tbl.pl line 9, <> line 3.