my $col="insert into table mytable ("; my $val="values ("; foreach (param()) { $col.="$_,"; $val.="?,"; push(@arr,param($_)); # Beware! this will break if any variables have multiple values. } $val=~s/,$//; $col=~s/,$//; $statement="$col) $val)"; $sth=$dbh->prepare($statement); $sth->execute(@arr);