You can find several suggested solutions to this problem at
Case-sensitive substitution with case-insensitive matches. Basically, you can use string bitwise xor for cleverness and speed, or transfer case character by character for robustness and portability.