my $stmt = "SELECT somedata FROM table WHERE id = $ids_to_match[0]"; for my $i ( 1 .. $#ids_to_match ) { $stmt .= " OR id = $ids_to_match[$i]"; }