Stricter validation can be necessary when using the modules
#!/usr/bin/perl use Regexp::Common; @exprs = qw(1 5.25 0.001 1.3e8 foo bar 1dd inf infinity 0x12 1_000_000 1,000,000); foreach $expr (@exprs) { print "$expr is", ($expr =~ /$RE{num}{real}/) ? '' : ' not', " a number\n"; } Output: 1 is a number 5.25 is a number 0.001 is a number 1.3e8 is a number foo is not a number bar is not a number 1dd is a number inf is not a number infinity is not a number 0x12 is a number 1_000_000 is a number 1,000,000 is a number