Update: As MeowChow's pointed out to me, it's not necessary to \Q\E within the substitition part of s/// for this to work, as well as in m// strings as well; code snippet has been updated to reflect this. Mainly, if you do so, realize any special symbols ('.', '{', '}', etc) wil be quoted (eg '.' to '\.'), if you do include the \Q\E.
use constant TEST => 3; my $string = "123456"; $string =~ s/\Q@{[ TEST ]}\E/9/; print $string, "\n"; # 129456 $string =~ s/2/@{[ TEST ]}/; print $string, "\n"; # 139456
In reply to Using constants inside regex by Masem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |