You wrote "DBD::CSV" eats memory in each loop". How do you know that? Your script doesn't do any memory testting or profiling or printouts. And if it's true, what OS are you on and what versions of the software and its prerequisites are you using? (your version of DBI, for example is more than 5 years old).