$sth->prepare("INSERT INTO Blah (a,b,c) VALUES (?,?,?)"); tie @list, 'Tie::File', $filename; while (@list) { my @insert = processRow($list[$#list]); #this splits the records into an array and does some data cleaning $sth->execute(@insert); #And check for errors and all that... pop @list; } untie @list; unless ($errors) { unlink $filename; } #### $sth->prepare("INSERT INTO Blah (a,b,c) VALUES (?,?,?)"); tie *TSV, 'File::ReadBackwards', $filename; while () { my @insert = processRow($_); #this splits the records into an array and does some data cleaning $sth->execute(@insert); #And check for errors and all that... truncate $filename, tell TSV; #pops the last line } untie *TSV; unless ($errors) { unlink $filename; }