If you literally want to clear the 2nd character from the end (i.e. byte 49 of 50 bytes), you could do this with substr:
substr($string, -2, 1) = undef;
That should neatly cut that character out of the string. My instincts tell me you're doing something "the hard way", though. I really cannot see the value of having a binary ^M sitting out near the end of ASCII text file lines. I would only expect to see that with improperly transferred files between systems that use incompatible newlines. I don't quite understand what you're trying to accomplish, but my gut tells me you're going about this problem (whatever your true problem is) the wrong way.
Good luck. | [reply] [d/l] |