in reply to sugession for the filecreating

You're trying to create a sequence, right? Please see http://forums.mysql.com/read.php?61,143867,145839#msg-145839

Update:

Often the database system you are working with already has a way of doing what you think you have to do in Perl. TAMTOWTDI ... but using the technique native to the database can work a lot faster and easier than home-brewing your own code.