my %xlat = ( F => '|', S => '^', T => '&', R => '~' E => '\\', ); while( m/ \G .*? \\([FSTRE])\\ /gsx ){ substr $_, pos() - 3, 3, $xlat{ $1 }; }