#!/usr/bin/perl use strict; use warnings; my @numbers = qw(1 -1 123.1 0.1 Characters); foreach my $number (@numbers) { checkInputStringWithSwitchConditions($number); } sub checkInputStringWithSwitchConditions { use Switch; switch ($_[0]) { case /^[+-]?\d+\z/ { print "The $_[0] is a +/- integer\n" } case /^[+-]?(?=\.?\d)\d*\.?\d*(?:e[+-]?\d+)?\z/i { print "The $_[0] is a C float\n" } case /\D/ { print "The $_[0] has nondigits\n" } else { print "Non of the cases where True\n" } } } __END__ The 1 is a +/- integer The -1 is a +/- integer The 123.1 is a C float The 0.1 is a C float The Characters has nondigits