in reply to substitution preserving capitilization

$text =~ s|\b($term)\b|<a href=x>$1</a>|ig;

Capturing your search term in case-insensitive mode still preserves the original case when you use the captured text in your replacement.

This matches on word boundaries, rather than the \W non-word characters you were using.