my %actions = ( greet => sub { print "Hello world!\n"; }, growl => sub { print "Rawwwrrrr!\n"; }, depart => sub { print "Goodbye!\n"; }, unrecognized => sub { warn "I don't know how to $_[0].\n"; }, ); while( ) { chomp; if( exists $actions{$_} ) { $actions{$_}->(); } else { $actions{unrecognized}->($_); } } __DATA__ greet growl whine depart #### Hello world! Rawwwrrrr! I don't know how to whine. Goodbye!