use strict; use warnings; use Term::ReadKey; $|++; #you must autoflush buffer or it print only at newlines ReadMode('cbreak'); print "How much is A:"; my $input; my $char; while ( $char = ReadKey(0) and $char =~/^\d$/ ){ $input.=$char; print $char; } print " A=$input\n";