http://www.perlmonks.org?node_id=1033511

newbie1991 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a list of names that I am trying to clean up. Some of them have ".replaced" after the name, which I am trying to remove. The code I am using is this :

$name = substr $name, 0, rindex( $name, q{replaced} );
The line works just fine for the names that are followed by the "replaced", however, the last letter of the name gets cut off if the name is not followed by "replaced". e.coli.replaced becomes e.coli (which is fine), but z.mays becomes z.may (which isn't). How can I fix this?