- First, you need to replace "\w\d+" with "\w+\d+". Otherwise, your regex is only going to match "x1.data" instead of "xxx1.data".
- Second, I assume you're using bash, sh, or a similar shell on a Unix box. When passing arguments using double-quotation marks, you need to escape any backslashes, dollar signs, and certain other characters. I recommend using single-quotation marks instead since most characters don't have to be escaped inside them.
Suggestion:
perl -npi.bak -e 's:(\w+\d+\.data):testname/$1:g' file1.txt