in reply to MySQL logic

In addition to the other suggestions above, I see you have:
my $dbh = DBI->connect("DBI:mysql:$dbase", $mysql_user, $mysql_pass) or print DBI=>"errstr";
where you probably mean
my $dbh = DBI->connect("DBI:mysql:$dbase", $mysql_user, $mysql_pass) or print DBI->errstr;