Your my $dbh defines a variable called $dbh which is initially set to undef. And then you call a method ->do on it. But (unless you use autobox, which almost nobody does for production code as it's just too weird) you can't call methods on undef.
I assume you actually want to use the $dbh variable you defined in main. Long term you want to read up about how scoping works in Perl. Short term a solution is to use $::dbh instead of $dbh, and don't use my in front of it. This acts as a global variable, so will be accessible from anywhere in your program. However, global variables are not a good idea, which is why long term you should learn how Perl scoping works.