in reply to Re^2: how to modify the text in file
in thread ho w to replace a occurence of string by other string

Aha !
perl -npi.bak -e "s:(\w\d+\.data):testname/$1:g" file1.txt
That is a shell quoting problem. Your $1 gets replaced by an (empty) environment variable before Perl sees it. Use single quotes:
perl -npi.bak -e 's:(\w\d+\.data):testname/$1:g' file1.txt