loop { my $x = prompt("Enter a number: "); redo unless $x ~~ /\d+/; last; }