use strict; my %command_list; my @cl; my $command; %command_list = ( #quit => \&end_program, greeting => \&greeting, #time => \&systime, #help => \&help, log => \&which_log # this one is new ); while (1){ $command = ; # assume $command="log start" @cl = split / /,$command; my $func = shift @cl; # first CLI argument is hash key if (!(defined($cl[0]))){ # had to add this to handle single word commands chop($func); } if (defined($command_list{$func})) { $command_list{$func}->(@cl); # passes rest of CLI args to handler } else { print "invalid command\n"; } } sub greeting { print "welcome\n" } sub start_logs() { print "Logs Started\n"; } sub stop_logs() { print "Logs Stopped\n"; } sub log_status { print "log status\n" } sub which_log { my $arg = shift; chop($arg); # newline here also... return start_logs() if ($arg eq "start"); return stop_logs() if ($arg eq "stop"); return log_status(); # default behavior }