use diagnostics; use 5.010; $num = int(1 + rand 100); print "input guess number here with 10 times: \n"; while(<STDIN>){ $times++ if $_=~ /\d+/; if($times > 10 || $_ =~ /^[quit|exit]/i){ print "the real number you was just guessing is $num\n"; print "You've try $times times.\n"; last; } print "Too high\n" if $_ > $num; print "Too low.\n" if $_ < $num; print "You're so great, you get it with $times times.\n" if $_ == $num; }