sub isThisADecimalNumber { my ($string) = @_; return $string =~ /^\s* -? # negative sign - optional (?: \d+ # digits (?:\.\d*)? # and an optional decimal and maybe more digits | # OR \.\d+ # a decimal and some digits ) \s*$/x; }