my $text = "abcDE\x08\x08xyz\x08Z"; # \x08 is the backspace character while ($text =~ m/\x08/g) { substr($text, pos($text)-2, 2, ''); } print $text, "\n"; # emits: abcxyZ