my %dispatch = ( start => sub { my @args = @_; # . . . }, # . . . ); while () { my ($cmd, @args) = split; exists $dispatch{$cmd} or warn 'Unknown command: ', $cmd and next; $dispatch{$cmd}(@args); }