I would like to restrict the part of a string a regexp is allowed to operate on, For example I would like to ignore comments. I would like $x = " andrew andrew # andrew " ; $x =~ s/andrew/black/g ; to produce " black black # andrew "