I don't remember enough about the way regular expressions are implemented these days, but wouldn't you want upper(r, n) in the case that n is non-zero to be or [null, seq [r, upper (r, n-1)]] I would think that it would be a bit more efficient.