in reply to special regexp

A pure regexp solution, although I would use jeroenes solution:

s{(x+)}{"x" x (length( $1) /2);}eg;