use Test::More 'tests' => 5; sub is_code { no warnings qw( void uninitialized ); return eval { defined &{$_[0]} }; } sub real_sub { die 'real sub called' } my $sub_ref = sub { die 'sub ref called' }; my $undef; ok( is_code( \&real_sub ), 'real sub ref is code' ); ok( is_code( $sub_ref ), 'lexical sub ref is code' ); ok( ! is_code( $undef ), 'undef is not code' ); ok( ! is_code( 'string' ), 'string is not code' ); ok( is_code( 'real_sub' ), 'string is code' );