I write a fair number of programs that use interactive commands. I intensely dislike programs that require me to type more than the minimum number of characters to distinguish one command from another. I also dislike have to have special parameters that instruct the command interpeter what portion of the command is unique.

To that end, this snippet takes a hash of commands, keyed by the command name, and the user input, and finds the minimum match. Errors are no matches, or ambiguous matches, in which case an error message with the list of commands is returned. If no error, the full name of the hash is returned.

You could easily take this one step further and give it the ability to then accept which command the user meant (like some shells do). By changing the 'ambiguous match' (you have it 'ambigous', BTW) part to create a hash. Actually, if you make @matched into %matched with the structure of: