use Term::ReadKey;

ReadMode 4; 

my $key = '';

while($key !~ /(Y|N)/i) {
    1 while defined ReadKey -1; 
    print "Type Y/N: ";
    $key = ReadKey 0; 
    print "$key\n";
}

ReadMode 0; 

print "\nYou typed: $key\n";