use Text::Abbrev; use strict; print "Enter a command: "; chomp(my $action = ); # they could enter 'adm' or 'h' my %modes = abbrev(qw( hsbn admin ... )); # if $modes{$action} is defined, that means it is a # NON-AMBIGUOUS abbreviation of 'hsbn', 'admin', etc. if (defined(my $fullaction = $modes{$action})) { if ($fullaction eq 'hsbn') { ... } elsif ($fullaction eq 'admin') { ... } ... } else { print "$action was ambiguous.\n"; } #### if ("hsbn" =~ /^$action/) { # $action is "h", "hs", "hsb", or "hsbn" } #### my $valid = join "\n", qw( hsbn admin help quit ... ); chomp(my $action = ); my @matches = $valid =~ /^($action.*)/mg; if (@matches == 0) { print "No command matched '$action'\n"; } elsif (@matches > 1) { print "Multiple commands matched '$action': [@matches]\n"; } else { print "You selected $matches[0].\n"; }