#!/usr/bin/perl use strict; use warnings; use 5.014; # juliosergio's test.pl print "Enter a number or string: "; my $s = ; chomp $s; if ( $s =~ /^[0-9,.E]+$/ ) { # char class, 1 or more of any of those specified say "$s is a number\n"; # & the ^...$ restricts what's tested. } else { say "'$s' may be a string\n"; # Not "isn't a number" } #### C:\>numVSstring.pl Enter a number or string: 123.2 123.2 is a number C:\>numVSstring.pl Enter a number or string: 1E3 1E3 is a number C:\>numVSstring.pl Enter a number or string: 17 17 is a number C:\>numVSstring.pl Enter a number or string: now is the time 'now is the time' may be a string C:\>numVSstring.pl Enter a number or string: III 'III' may be a string