use Guard; sub foo { # This will warn $guard = scope_guard { print "done\n" }; ... do stuff, without ever mentioning $guard again ... };