sub empty ($) :lvalue { if ($_[0]) { require Carp; if (eval { require PadWalker }) { my $varname = PadWalker::var_name(1, \$_[0]); Carp::croak("$varname is not empty, stopped"); } Carp::croak("Variable is not empty, stopped"); } $_[0]; } # Asserts that $var1 is "empty" (i.e. the empty string, 0, or undef) and assigns $var2 as the new value. empty $var1 = $var2; # Can also be used like this to assert $var1 is empty without assigning a new value. empty $var1;