rename ($was, $_) unless $was = $_;
will always evaluate true because because you are using the assignment operator (
=) not the string equivalence operator (
eq). You should have gotten a warning about that one running the posted code.
Reading Basic debugging checklist may be helpful. An essential element is use print/say and/or Data::Dumper to make sure variables contain what you think they should.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.