I agree with previous posters that you have likely snipped the cause of the issue from your example. Is it possible to create a simplified script that demonstrates the problem in a way that doesn't give up restricted information?
Also, just in relation to connecting to your DB, I strongly suggest you use something similar to the following:
my $sqlserver = 'SERVERNAME';
my $sqldb = 'DBNAME';
my $dbs = "dbi:ODBC:Driver=SQL Server;Database=$sqldb;Server=$sq
+lserver;Trusted_Connection=yes";
my $dbhandle = DBI->connect($dbs, undef, undef, {RaiseError => 1, Aut
+oCommit => 1}) or die DBI->errstr();
That
Trusted_Connection=yes means the user account configured to run the script is the one that is used to authenticate and you don't have to store any passwords anywhere. Specifically setting AutoCommit also makes you consciously think about your work-flow. If you're running essentially bulk operations, committing after every statement can severely limit your performance.