in reply to my and its use

It's because of the or die part:
|| die "Cannot connect!: $!\n$dbh->errstr";
You are referencing $dbh on the same line, so declare $dbh before you try to connect.

Jeff