Here's an example of preparing DBI statements with variable numbers of placeholders. This is especially useful when writing a statement such as:
SELECT * FROM my_table WHERE id_column IN (?, ?, ?, ?)
where the number of placeholders is unknown at compile time.

Note that the first three occurences of @values are in a scalar context.

my @sths; while (<>) { my @values = split ' ', $_; $sths[@values] ||= $dbh->prepare("SELECT * FROM my_table WHERE id_column IN (" . join(', ', ('?') x @values) . ')'); $sths[@values]->execute(@values); # ... }