you
donīt use strict;
donīt use the two argument form of bless();
donīt get a reference to self in your method
use the bareword self where you mean $self in new()
That is what causes the wrong behavior of your class.
Compare to this code (that works as intended):
use strict;
my $p = Foo->new();
$p->bkg_img("whatever");
$p->print_html;
package Foo;
sub new
{
my $class = shift;
my $self = {};
$self->{BKG_IMAGE} = "image";
bless($self, $class);
return $self;
}
sub bkg_img
{
my $self = shift;
$self->{BKG_IMAGE} = $_[0];
}
sub print_html
{
my $self = shift;
print <<"HTML";
$self->{BKG_IMAGE}
HTML
}