use Carp; opendir(DIR, $dir) or ($error = carp("Could not open $dir"); (mail($error) and croak) if $error; sub mail { my $error = $_[0]; ... }