$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; }