If I had to guess, you're not executing the execute command in your else clause. Looking at it, you're going through an array and as long as the element in the array does not equal '', you're executing. However, what if the array never holds anything? The array is being based off of
foreach my $rec (sort(keys(%workOrder))
{
@workOrders=@{$workOrder{$rec}};
}
Your code doesn't assign any value to the hash workOrder so I imagine the array workOrders is also empty. Do a print before your execute to see if the code ever enters the else block.
Update:
Standard things: use strictures, use warnings, and use more distinct variable names. I don't think I am correct about your problem.
Check the DBI->connect() and $dbhST->prepare() succeeded