foreach my $record (@filedata) { my @fields = split /,/, $record; my $placeholders = "?," x scalar (@fields); chop $placeholders; # remove the end ',' my $sql = "INSERT INTO $table VALUES ($placeholders)"; my $sth = $dbh->prepare($sql); my $rows = $sth->execute(@fields); $sth->finish(); }