if ($input =~ /^[0-9]+$/) { # work with $input here } else { die "Please enter an integer\n"; }