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"; }