I think your question is better suited for the help mailing list? I would argue it has nothing to do with GNU Octave at all. Please, next time be aware of that.
Since i started to answer, i'll give you one last advise. Your use case is a typical scenario for regular expressions, you can define a template string containing markers, for instance:
function y = f(x)
foo = $foo;% do somethingend
and replace all occurrences of $foo by the actual value. If you have a recent compiler, you can use C++11 regular expressions, if not use Boost.Regex (where the standard is based upon) or Boost.Xpressive.