#!perl use strict; use warnings; use FileHandle; use Test::MockObject::Extends; my $mock= Test::MockObject::Extends->new(FileHandle->new); $mock->set_false( 'print' ); $mock->fake_new('FileHandle'); my $a = FileHandle->new; $a->open(">K") or die "could not open"; print {$a} "hello" or die "I expect to die here"; $a->print("hello") or die "I expect to be dead before we get to this point";