if (/ ^ (?: (?: -? \d+) | (?: -? \d+ \. \d+)) $ /x)
say 'Yes, ', $_, ' is a number';
say 'No, ', $_, ' is not a number';
2:17 >perl 417_SoPW.pl
Yes, 4 is a number
Yes, -7 is a number
Yes, 0.656 is a number
Yes, -67.35555 is a number
No, 5. is not a number
No, 56F is not a number
No, .32 is not a number
No, -.04 is not a number
| is bitwise-OR outside a regex, and alternation in a regex. For logical OR, use || (or or).
Within a regex, a dot matches any character. To match the decimal point, you need to escape it: “\.”.
Prefer chomp to chop — the former removes a line-termination if present, the latter removes the last character regardless.
Hope that helps,