#!/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__