#!/usr/bin/env perl use strict; use warnings; for (qw{1 two -3 3.4 zero 0}) { print "$_ is ", get_num_type($_), "\n"; } sub get_num_type { my ($num) = @_; my $num_type; NUM_TYPE_TEST: { if ($num !~ /^-?\d+$/) { $num_type = 'non-integer'; last NUM_TYPE_TEST; } if ($num < 0) { $num_type = 'negative'; last NUM_TYPE_TEST; } if ($num == 0) { $num_type = 'zero'; last NUM_TYPE_TEST; } if ($num > 0) { $num_type = 'positive'; last NUM_TYPE_TEST; } } return $num_type; }