#!/usr/bin/env perl use strict; use warnings; use constant { NUM => 0, EXP => 1, }; use Test::More; my @tests = ( [1, 1], [0, 1], ['NaN', 0], ['Infinity', 0], ['-123.', 0], ['-123. ', 0], ['-123.0', 1], ['-123 ', 0], ['000', 0], ['007', 0], ); plan tests => 0+@tests; my $re = qr{(?x: ^ # anchor at start [+-]? # optional leading sign [0-9]+ # 1 or more ASCII digits (?: \. # literal decimal place [0-9]+ # 1 or more ASCII digits | # OR # nothing ) $ # anchor end )}; for my $test (@tests) { is $test->[NUM] =~ /$re/, !!$test->[EXP], "Test that '$test->[NUM]' is " . ($test->[EXP] ? 'VALID' : 'INVALID'); } #### 1..10 ok 1 - Test that '1' is VALID ok 2 - Test that '0' is VALID ok 3 - Test that 'NaN' is INVALID ok 4 - Test that 'Infinity' is INVALID ok 5 - Test that '-123.' is INVALID ok 6 - Test that '-123. ' is INVALID ok 7 - Test that '-123.0' is VALID ok 8 - Test that '-123 ' is INVALID not ok 9 - Test that '000' is INVALID # Failed test 'Test that '000' is INVALID' # at ./pm_11146401_is_number.pl line 42. # got: '1' # expected: '' not ok 10 - Test that '007' is INVALID # Failed test 'Test that '007' is INVALID' # at ./pm_11146401_is_number.pl line 42. # got: '1' # expected: '' # Looks like you failed 2 tests of 10.