use strict; use warnings; my $word = shift; my @words = qw(lock tubes on raider dispersion offset fire all torpedoes); my $pat = quotemeta($word); my @matches = grep (/^$pat/, @words); if(@matches == 0) { print "Unknown command \"$word\"\n"; } elsif(@matches == 1) { print "Recognized \"$word\" as command $matches[0]\n"; } else { print "Ambiguous command \"$word\" could be any of: @matches\n"; }