in reply to how to make sed case INsensitive

Did you know that Perl can do just about everything sed can do? A straight-across port might be:

system qq|perl -e 's/$search/$replace/gi' $write > $write2|;

I'd likely do it in-process, though.