in reply to print htmlcode issue

Welcome to the monastery :)

First off, why would you want to assign a print to a variable ? Why not just assign the string itself ?

my $test = " ZXCXlala blub hey ";

works just as well ... print $test; will work as expected.
Of course you could also do

my $test = <<HTML SGSDF aSDGAWR HTML ;

if you want to use HERE-Documents.

You can probably play games with STDIN and STDOUT, but that's really not needed here at all ...