in reply to Anonymous sub as error handler

The reason you get the error is that (at a guess) the if statement between the code dereference braces is run and then the result of the last statement executed is then attempted to be dereferenced, and obviously fails.

You could achieve the execution of an anonymous sub in a few ways (there's a bunch more than listed below but they're really a variation on a theme)

$sth->execute() || sub { ... }->(); # or $sth->execute() || &{ sub { ... } }(); # alternatively $sth->execute() || do { ... };
Of course you'll probably just want to restructure your code as that is a much saner route.
HTH

_________
broquaint