echo "a#b#c#d" | tr '#' '\n' | perl -pe 's/b$^c/bc/mg'