my $x = some_sub(); if ( $x > 2 ) { # do something here } #### if ( defined $x && $x > 2 ) {} #### #!/usr/bin/perl use Benchmark; use strict; my ( @nums, $x ); for (1..1000) { my $r = int(rand(5)); push @nums, $r > 0 ? $r : undef; } timethese(-10, { Test_defined => 'for (@nums) { if ( defined $_ and $_ > 2 ) { $x++ }}', Do_not_test => 'for (@nums) { if ( $_ > 2 ) { $x++ }}' }); #### Benchmark: running Do_not_test, Test_defined, each for at least 10 CPU seconds... Do_not_test: 11 wallclock secs (10.01 usr + 0.00 sys = 10.01 CPU) @ 365830.27/s (n=3661961) Test_defined: 8 wallclock secs (10.02 usr + 0.00 sys = 10.02 CPU) @ 363485.63/s (n=3642126)