I'm not sure if I understood your advice, but I changed this:
my $text = <$fh>;
$text .= <$fh>;
But I still get the same result. Is that what you mean by read the file line by line? When I did this kind of read on "pure Perl" I used:
open FL, "<"."file.txt";
And it worked fine, but now I'm sending the file from a html page(<input type="file"...) so I don't know any other way to get the file handle besides that.
Thanks for the help and sorry about the stupidity, I'm just a beginner on perl programming.