my @fields = qw/CLIENT RECORD CONTROL CUSIP .../; ... # open file and run sanity checks my $columns = join ',', @fields; # create the correct number of placeholders my $placeholders = join ',', ('?') x @fields; my $sql = "INSERT INTO table ($columns) values ($placeholders)"; my $sth = $dbh->prepare($sql); while ( defined $line = ) { chomp $line; my @data = split /\t/, $line; ... # probably should check to see if all the fields are defined. # then insert using our statement, passing the values of @data to # replace the placeholders in the SQL statement $sth->execute(@data); }