my %commands = ( cmd1 => \&do_cmd1, cmd2 => \&do_cmd2, .... ); #### ## untested, just something I thought up right now chomp( $input = ); my( $cmd, @args ) = split( /\s+/, $input ); if( defined( $commands{ $cmd } ) ) { $command{ $cmd }->( @args ); }