http://www.perlmonks.org?node_id=953987


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;