use Tk; my $x = 0; tkinit->Entry(-textvariable=>\$x,-validate=>'key', -validatecommand=>sub{ return 0 unless $_[0]=~/^\d+$/; 1; })->pack; MainLoop;