#!/usr/bin/perl -w use strict; my @numbers = ('-1', 1, 1000, '0001', 'abc', 34, '0x65', "1.2", '3.', '.3'); sub is_numeric { return $_[0] =~ /^[1-9][0-9.]*$/ } for (@numbers) { if (is_numeric($_) ){ print "$_ is numeric\n"; } else { print "$_ is NOT numeric\n"; } } __END__ -1 is NOT numeric 1 is numeric 1000 is numeric 0001 is NOT numeric abc is NOT numeric 34 is numeric 0x65 is NOT numeric 1.2 is numeric 3. is numeric .3 is NOT numeric