I have code like:
#!/usr/bin/perl
use strict;
use warnings;
open(IO,"<source.html");
my $variable = do {local $/; <IO>};
chomp($variable);
print $variable;
However when I print it, it still has newlines?
It removes the last newline.
Since you're slurping in the whole file, you're going to have to do a regex substitution to get rid of them:
$variable =~ s/\n//g;