#!/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'); }