if ($number =~ /[-.]+/) if ($number =~ /\D/) into just one regex: if( $number =~/[-.\D]/) { print "Invalid!! Only unsigned integer numbers >=0 are allowed!\n"; next; } probably could add if( $number =~/[-.+\D]/) also to disallow the + sign. But I don't this minor issue detracts from the main point.