in reply to regular expression

Untested:
s/([0-9]{6})([0-9]+)([0-9]{4})/$1 . ("X" x length $2) . $3/e;