if ($command eq "add") { .... } elseif ($command eq "view") { .... } elseif ($command eq "something") { .... } elseif ( ... ) { .... } elseif ( ... ) { .... } elseif ( ... ) { .... } elseif ( ... ) { .... } elseif ( ... ) { .... } elseif ( ... ) { .... . . . . } #### %menus = ( 'first' => { 'add' => '&add', 'view' => '&view', 'a' => '\$menus{first}{add}', 'v' => '\$menus{first}{view}', }, 'second' => { 'delete' => '&delete', 'print' => '&print', }, ); #### $menus{first}{$_} if exists $menus{first}{$_}; or print "Command not found.\n" if not exists $menus{first}{$_};