my $test = $b; $test =~ s/\s+//g; if ($test != 0) { $test =~ s/[1-5]//; print "It is either 1,2,3,4,5\n" if ! $test and $test ne "0"; }