in reply to Substitutions are happening in the wrong place

 /<a href="#use\(\)">/ your parens are putting '' into $1... you need to escape them

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