my $tag = 'jane'; while ( ) { s/($tag)/##$1##/i; # you might also want a /g here as well. print; } __DATA__ - John is following jane - John is following Jane