test2(1.00.000); ##```## test2("1.00.000"); ##``````## sub test2 { my (\$var2) = @_; return ("One") if (\$var2 =~ /^1/ ); return ("Two") if (\$var2 == /^2/ ); return ("Three") if (\$var2 == /^3/ ); return undef; } ##``````## sub test2 { my (\$var2) = @_; return ("One") if (\$var2 =~ /^1/ ); return ("Two") if (\$var2 =~ /^2/ ); return ("Three") if (\$var2 =~ /^3/ ); return undef; } ##``````## sub test2 { my \$var2 = substr shift, 0, 1; return ("One") if \$var2 == 1 ; return ("Two") if \$var2 == 2 ; return ("Three") if \$var2 == 3 ; return undef; } ##``````## use strict; use warnings; my @translation = qw / Zero One Two Three/; sub test2 { return \$translation[(substr shift, 0, 1)]; } print test2("1.00.000"); ##``````## use strict; use warnings; use Benchmark qw/cmpthese/; my @translation = qw / Zero One Two Three/; sub test1 { my \$var2 = shift; return ("One") if (\$var2 =~ /^1/ ); return ("Two") if (\$var2 =~ /^2/ ); return ("Three") if (\$var2 =~ /^3/ ); return undef; } sub test2 { my \$var2 = substr shift, 0, 1; return ("One") if (\$var2 == 1 ); return ("Two") if (\$var2 == 2 ); return ("Three") if (\$var2 == 3 ); return undef; } sub test3 { return \$translation[(substr shift, 0, 1)]; } cmpthese( -1, { test_1 => sub {test1("3.01.000")}, test_2 => sub {test2("3.01.000")}, test_3 => sub {test3("3.01.000")}, } ) ##``````## \$ perl test_if.pl Rate test_1 test_2 test_3 test_1 1294050/s -- -11% -51% test_2 1451608/s 12% -- -45% test_3 2642856/s 104% 82% -- ```