Slight variation so you don't need the length:
substr($str, 6, -4) =~ s/./X/g; [download]
In reply to Re^4: regular expression by Crackers2 in thread regular expression by Anonymous Monk