open(FILE, 'H:\mer586.txt') or die "Unable to open file: $!\n"; use Win32::OLE; use Win32::OLE::Const 'Microsoft ActiveX Data Objects'; my $conn = Win32::OLE->new('ADODB.Connection'); $conn->open('1099s'); $loop = 0; print "Processing...."; while () { # find the client's taxid, and then look for the payee's taxid, either a ssn, or a real taxid if (/\s*22-222222\s*((\d*\-\d*\-\d*)|(\d+\-\d*)|(\d\d\d\d\d\d\d\d\d))/) { $taxid = $1; } # next, the line contained the payee's name and the amount they were paid, so I had to strip that all away # plus get the whole dollar and cents amount if (/(\s*|\t*)((([A-Z])*|(\s|\t)*)|(([A-Z])*(\s*|\t*)([A-Z])*))*(\t*|\b*|\s*)((\d*)|(\d*\,\d*)|(\d*\,\d*\,\d*))(\.\d*)/) { $amount = $11; $amount .= $15; } # once I hit the company name, I know I'm ready to grab the next set of records.... if (/COMPANY NAME, INC/) { undef $taxid; undef $amount; } if (($taxid) && ($amount)) { # I only want to insert when I have both... $sqlString = "INSERT INTO 1099Data(ProvTaxID, DollarAmount) VALUES (\'$taxid\', \'$amount\');"; $conn->execute($sqlString); print "\n\n\tUH-OH: ", Win32::OLE->LastError(), "\n" if (Win32::OLE->LastError()); exit if (Win32::OLE->LastError()); undef $taxid; undef $amount; } print "." if (++$loop % 300 == 0); # let me know this is still running } $conn->close if ($conn); print "Finished!\n";