Raw Input
aa@bb\cc\@dd\\@ee\@
a\@bc\\de@\f\\@g\@h
Desired Output
aa#bb\cc\@dd\\#ee\@
a\@bc\\de#\f\\#g\@h
Script and Comments
Script1
[ 1] :loop
[ 2] s/^((\\.|[^\\@])*)@/\1#/
[ 3] t loop
Comments
  1. '-r' option of GNU sed must be used which make sed interpret regular expressions as Extented REs.
  2. Substitutions occur from right to left.
  3. DFA(deterministic finite automata) for capturing non-escaped '@':
Script2 [perl]
[ 1] while(s/^((?:\\.|[^\\@])*)\@/$1#/)
[ 2] { }
Comments
  1. Substitutions occur from right to left.
Script3 [perl]
[ 1] s/\G((?:\\.|[^\\@])*?)\@/$1#/g;
Comments
  1. Substitutions occur from left to right.