#!/usr/bin/perl use warnings; use strict; use Term::ReadKey; #passing ReadKey() an argument of -1 to indicate not to block: ReadMode('cbreak'); while(1){ my $char; if (defined ($char = ReadKey(0)) ) { print "$char->", ord($char),"\n"; # input was waiting and it was $char if(ord($char) == 113){ print "Got a q\n"; print "Do your thing here\n" } if(ord($char) == 27){ print "Got an Escape\n"; exit; } } else { # no input was waiting } } ReadMode('normal'); # restore normal tty settings