use Scalar::Util qw( looks_like_number ); use List::Util qw( first ); my @menu = ( 'Known star', 'Create a new star', 'List Known Stars', 'Quit' ); my $input = '...'; my $picked; if ( looks_like_number $input ) { $picked = $menu[ $input - 1 ]; } else { $picked = first { length $input <= length $_ and lc $input eq lc substr $_, 0, length $input; } @menu; } if ( !defined $picked ) { die "What do you mean by '$input'?"; }