Python 3.5, 72 ========== def f(a,b):b=[*b];return"".join(y==b[0]and b.pop(0)or"#"for y in a if b) Ungolfed: def f(a, b): b = [*b] #Convert string to list; yeah Python 3.5 c = [] for y in a: if b and y==b[0]: c.append(b.pop(0)) else: c.append("#") return "".join(c) Try it [here][1] [1]: https://repl.it/CO1y/1