#!/usr/bin/perl use strict; use warnings; use diagnostics; use Term::ReadKey; my $count = 0; my $char = undef; ReadMode('cbreak'); while (!defined $char) { $char = ReadKey(-1); $count++; } print "$count\n"; # Put the terminal back the way you found it. END { ReadMode('restore'); }