I found the solution using lua instead subs_filters. In nginx configuration file I added the following directives
set $a mysourcestr;
set $b mydeststr;
body_filter_by_lua_file /path/lua/scripts/subs.lua;
then I wrote a lua script very simple
#!/usr/bin/lua
-- /path/lua/scripts/subs.lua
response_body = ngx.arg[1]
response_body = response_body:gsub(ngx.var.mysourcestr,ngx.var.mydeststr)
ngx.arg[1]=response_body