For your scenario, don’t worry about variable substitution. You can do what you need with a simple Java service. E.g.:
This service takes an input string called ‘key’ and returns a string called ‘value’. ‘key’ is the name of the variable whose value you want and ‘value’ is that value.
As you can imagine, true nested substitution would be extremely challenging using percent signs only (or any single character) because, for example, you could have a scenario such as %a%b%c% which could mean different things, like + ‘b’ + or <value of <‘a’ + + ‘c’>>
If you make an assumption that nested substitution will always take the simplistic form of %%variable%% … %%%%%variable%%%%%, you should be able to easily write your own service using the PSUtilities code and the code above as a reference.