Recursive replace in complex output