in reply to Re^3: regular expression
in thread regular expression

Slight variation so you don't need the length:

substr($str, 6, -4) =~ s/./X/g;