my @company_ids = qw(10 15 20); # for example my $where = 'where company_id in (' . join(',', @company_ids) . ')'; # insert the where clause at the bottom of the sql $sql = END_SQL; select comp_name from companies $where END_SQL