my $bar = sub { # do something here }; $bar->(); # executes the stuff in the anonymous sub above #### sub foo { # do something here } my $bar = \&foo; $bar->(); #executes the stuff in foo() #### my %actions = ( foo => \&do_foo, # some long operation bar => sub { # some short one line thing }, default => sub { # do something by default }, ); my $request = $cgi->param('request'); if( exists($actions{ $request } )) { $actions{ $request }->(); } else { $actions{ default }->(); }