Replace variable \(x\) in expression with a list.
L:=[x, x^2,y,z]: f:=proc(X::anything,x::symbol) local la,y; if patmatch(X, conditional( y::anything, _has(y,x) ),'la') then eval(y,la); eval(%,x={a,b}); else X; fi; end proc; map(X->f(X,x),L); [{a, b}, {a, b}^2, y, z]
Actually, we do not need patmatch for this, but the above is just an exercise. This can be done in one line in Maple as follows
In Mathematica
{x, x^2, y, z} /. x -> {a, b} {{a, b}, {a^2, b^2}, y, z}