Python 3.5, 82 ========== i=input a,b=[*i()],[*i()] print(*[y==b[0]and b.pop(0)or"#"for y in a if b],sep="") Try it [here][1] [1]: https://repl.it/CO1y/0