It doesn't need to be an open handle. You can use tie *FH, ... out of the blue. You can use tie local *FH, ... for something localized.
$ perl -e'
use v5.40;
use feature qw( bareword_filehandles );
use Tie::Simple qw( );
tie *FH, Tie::Simple::, undef,
PRINT => sub {
shift;
my $msg = join( defined( $, ) ? $, : "", @_ );
$msg .= $\ if defined( $\ );
say STDOUT "[$msg]";
};
say FH "Hello!";
'
[Hello!
]
Without bare word file handles:
$ perl -e'
use v5.40;
use Symbol qw( gensym );
use Tie::Simple qw( );
my $fh = gensym;
tie *$fh, Tie::Simple::, undef,
PRINT => sub {
shift;
my $msg = join( defined( $, ) ? $, : "", @_ );
$msg .= $\ if defined( $\ );
say STDOUT "[$msg]";
};
say $fh "Hello!";
'
[Hello!
]