use Term::ReadKey; if (defined ($char = ReadKey(-1)) ) { if(ord($char) == 27) { ... } }