$sqlfmt = "SELECT val1,val2,val3 where val1 = %d"; foreach (@values) { $sql = sprintf($sqlfmt, $_); }