in reply to Search Term Highlighting

A simple solution may be:
$texttosearch =~ s/$searchstring/"<FONT COLOR='$color'><B>$searchstrin +g<\/B><\/FONT>/gi;
Which just combines two lines of your code. Note the escaped /s in the regular expression.
In fact, thinking about it, ditch the subroutine as this is a one line solution.
Update: Oops, as has been pointed out in the replies below, the () and $1 method is the way preserve the case. Should have checked my code I guess.

Replies are listed 'Best First'.
RE: RE: Search Term Highlighting
by librarygeek (Novice) on Jun 15, 2000 at 02:23 UTC
    This doesnt seem like it is any different from my code except that it is on one line. The problem is that if $searchstring contains "foo" and $texttosearch contains "Foo" (note the case difference) when the replace occurs $texttosearch now contains "foo" instead of "Foo". The code provided by sean does however solve the problem. Thanks for your suggestion though.