You can do this:
Dear $name,
some text with other variables like $age or $name again,
the $undefined will not be replaced.
greatings $me
$
Output against your XML sample:
Dear Test,
some text with other variables like 20 or Test again,
the $undefined will not be replaced.
greatings Me