I have perl script that has the following line in it:

Code:
 $line =~ s/^$oldLabel$|^$oldLabel(\W)|(\W)$oldLabel(\W)|(\W)$oldLabel$/$2$4$newLabel$1$3/ig;
This code works fine, however if I try to run it with perl -w or use warnings then it will give me alot of warnings basically saying that the $1-$4 variables aren't defined. Is there a better way to do what I'm trying to do in this line?