my %options = ( one => sub { print "one\n"; return 1; }, two => sub { print "two\n"; return 1; }, three => sub { print "three and break the loop\n"; return 0; }, '' => sub { print "Default\n"; }, ); #### if( exists $dispatch{ $action } ) { $dispatch{ $action }->(); } else { $default->(); } #### &{ $dispatch{ $action } || $default }(); #### while ( chomp( my $opt = ) ) { &{ $options{ $opt } || $options{ '' } }() or last; }