Scanmap() give us the recursion we want. Thanks. A slightly different question. Is there is a technique which will factor parts of an expression, e.g. xp : a*y+a*b*z+a*x+d => a*(y+b*z+c*x) * d