http://www.perlmonks.org?node_id=791650

bgupta has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I am trying to distinguish between numeric and string scalar values using regular expression as the below code.
my $var = { 'key1' => '1', 'key2' => 1 }; print "Key1: It is a number\n" if ( $var->{'key1'} =~ /^-?\d/ ) ; print "Key2: It is a number\n" if ( $var->{'key2'} =~ /^-?\d/ ) ;
But it is always getting interpreted as a number. Could somebody help me distinguish between the values '1' and 1 as in the above code