#!/usr/bin/perl use DBI; use Data::Dumper; my $dbh = DBI->connect( dsn, user, pass, { RaiseError => 1 } ); my $query = qq{ select * from blah_table where col1 = :p0 union select * from blah_table where col1 = :p0 union select * from blah_table where col1 = :p0 }; my $dbhq = $dbh->prepare( $query ); my @args = ('foo_param'); while( $query =~ /(:p(\d+))/g ) { #$1 will be :p0, $2 will be 0 $dbhq->bind_param($1, @args[$2]); #':p0 gets @args[0] } $dbhq->execute(); print Dumper($dbhq->fetchall_arrayref()); #### ... my $query = qq{ select * from blah_table where col1 = :p0 union select * from blah_table where col1 = :p0 union select * from blah_table where col1 = :p1 union select * from blah_table where col1 = :p0 union select * from blah_table where col1 = :p1 }; ... my @args = ('foo_param0', 'foo_param1'); ...