Here it is with line-by-line processing, saving to a different output file:
open IN, "<test.txt";   # input file
open OUT, ">test2.txt"; # output file

while( <IN> ) {       # read a line from IN into $_
    s/\bRR_/TT_/g;    # global substitute on $_
                        # (\b means word boundary)
    print OUT $_;     # write $_ to OUT

close IN;               # close files
close OUT;
If the file is not too big you can change it in place using file-slurping mode:
undef $/;              # enable file-slurping mode
open IN, "<test.txt";
$str = <IN>;           # slurp in whole file
close IN;
$str =~ s/\bRR_/TT_/g; # substitute
open OUT, ">test.txt";
print OUT $str;        # write whole file
close OUT;