Your file has line endings \r\n . chomp removes \n ( Newline ), but leaves \r ( Carriage Return ). Using Data::Dumper with Useqq , you can check the variable:
use Data::Dumper; $Data::Dumper::Useqq = 1; print Dumper($filename);
This should output something like:
$VAR1 = "temp/file1\r.xml";
In normal printing, it will display temp/file , move the cursor to the beginning of the line, and overwrite temp with .xml .
To remove line endings, replace chomp with:
s/\r\n$//;
or as @Borodin pointed out :
s/\s+\z//;
which "has the advantage of working for any line terminator, as well as removing the trailing space, which is usually undesirable"
source share