my $insert_snp_sql = "insert into $tableName (Chr, Pos_start, Pos_end, id, reference, genotype) values (?,?,?,?,?,?)"; my $sth = $db->prepare ($insert_snp_sql); while(){ #process input line and then insert to database if ($sth->execute($data[0],$data[1],$data[2], $data[3], $data[4],$data[5])) { #insert ok } }