my @anzahl; my $tableinhalt = qq!CREATE TABLE daten(!; for my $key ( keys %new ) { my $all_strings = join " ", @{ $new{$key}->{strings} }; my $length = $new{$key}->{laenge}; next unless $key; push @anzahl, $key; $tableinhalt .= qq!$key varchar ($length) NOT NULL,!; } $tableinhalt .= ')'; $tableinhalt =~ s/,\)/\)/; my $dbtable = $dbh->prepare($tableinhalt); $dbtable->execute; if($#anzahl == 0){ $insertvalue = qq!insert into daten ($anzahl[0]) value(?)!; my $sth = $dbh->prepare($insertvalue); $sth->execute(...); } elsif($#anzahl == 1){ $insertvalue = qq!insert into daten ($anzahl[0],$anzahl[1]) value(?,?)!; my $sth = $dbh->prepare($insertvalue); $sth->execute(...); } elsif($#anzahl == 2){ $insertvalue = qq!insert into daten ($anzahl[0],$anzahl[1],$anzahl[2]) value(?,?,?)!; my $sth = $dbh->prepare($insertvalue); $sth->execute(...); } ...