in reply to do-while loop

One way you can get code to do what you want would be with:

#!/usr/bin/perl use strict; use warnings; print "\nPick a letter between a and d.\n"; chomp(my $reply = <STDIN>); while ($reply !~ /^[a-d]$/i) { print "Please enter only a letter between a and d.\n"; chomp($reply = <STDIN>); }

This code will stay in that while loop until it gets an acceptable response. A couple notes on how it works:

  1. Note the use strict;use warnings at the top of the script. If you are not familiar with these, I would suggest you become so, since they can save you a good bit of debugging headache.
  2. In order to check the input, I use a regular expression. The pattern starts at the beginning of the expression (^), matches one character between a and d inclusive ([a-d]) and then must stop at the end of the expression ($). The modified i makes the match case insensitive. The binding operator !~ is the 'not-matching' operator, so if the contents of $reply do not match the pattern, you stay in the while loop. See perlre and perlretut for info on regular expressions.
  3. In your original code, you use the scalar operator ne on a list. This puts the list in scalar context and hence returns the length of the list, not a comparison against elements. You would only exit, therefore, when $reply was '4'.

Hope this clears things up. Welcome to the monastery.