perl -le '$t="John is following jane"; $t=~s/(jane)/##$1##/i; print $t' John is following ##jane## $perl -le '$t="John is following Jane"; $t=~s/(jane)/##$1##/i; print $t' John is following ##Jane##