You're declaring $dbh (which results in a new variable), and then immediately calling do on it! Of course it'd be undef. You'll need to do something to connect o the database before you use the database. Perhaps simply removing my $dbh from that subroutine will work, but I don't know what WebDB does.