my @vdbhosts = sort @lines; foreach my $i (0..$#vdbhosts) { print " " . $i + 1 . ". $vdbhosts[$i]\n"; } print "\n"; #### my ($userinput) = (<> =~ /([0-9]+)/g); die "User did not input a number" unless defined $userinput; die "User's number ($userinput) is out of range" unless (0 < $userinput and $#vdbhosts >= $userinput - 1); print "Your choice was number $userinput which is " . $vdbhosts[$userinput - 1] . "\n";