You can do this with $regsubex simply:
Code:
on ^*:text:*:#test_bot:{ 
  if (%backwards == on && $nick == PersonY) {
    echo -mbflt # $+(<,$nick(#,$nick).pnick,>) $&
      $regsubex($1-,/(.)/gS,$mid(\A,-\n,1))) | haltdef
  }
}