in reply to Substitutions are happening in the wrong place
Update sorry... putting \Q \E around a variable will take care of escaping non word characters in the variable so \Q$links{$_}\E in your regexp - Ant