my @matching=grep { 0 == index $_, $userinput } @commands;
####
#!/usr/bin/perl
use strict;
use warnings;
my @commands=qw/foo bar baz/;
print "Choose command [@commands]\n";
{
chomp(my $cmd=);
my @ok=grep { 0 == index $_, $cmd } @commands;
print "You chose [@ok]\n" and last if @ok==1;
warn +(@ok>1 ?
"Ambiguos command [@ok]" :
"Invalid command"), ", retry!\n";
redo;
}
__END__
####
$ ./foo.pl
Choose command [foo bar baz]
fred
Invalid command, retry!
fo
You chose [foo]
$ ./foo.pl
Choose command [foo bar baz]
ba
Ambiguos command [bar baz], retry!
bar
You chose [bar]