My guess is that $output contains a "\r" at the end.
#! /usr/bin/perl
$somenum=5;
$output="text.txt\r";
$output2="text.txt";
print " $somenum means that, $output has info.\n";
print " $somenum means that, $output2 has info.\n";
#OUTPUT
# has info.s that, text.txt
# 5 means that, text.txt has info.
Without more context I can't provide more help.
To get rid of a carriage return you can:
$output =~ s/\r//g;
Update: The OP changed the post so most of the info is out of context. The last remark should answer the current question.