use strict; use warnings; my $str; my $self = bless {}; open $self->{fh}, '>', \$str; my $fh = $self->{fh}; # Perl gets confused unless globs are simple scalars print $fh "Hello world\n"; close $self->{fh}; print $str; #### Hello world