$foo if defined $str and length $str; #### $foo if $str; #### BEGIN { *CORE::GLOBAL::length = sub(;$) { defined $_[0] ? CORE::length( $_[0] ) : undef; }; } #### $foo if length $str;