my @menu = ( "Go left", "Go right" ); for my $i ( 0 .. $#menu ) { print $i+1, ") $menu[$i]\n"; } print "?"; $_ = <>; ($_) = /^(\d+)/; # extract just the digits, if any. $_--; # because the menu as displayed in 1-based. # now do whatever you want with the number in $_ and # the full text of the selected menu item in $menu[$_].