... $file = File->new('t/file7.test'); eval { # declare as local so default is restored on block exit local *CORE::GLOBAL::read = sub (*\$$;$) { return undef }; # method that calls read() # the above causes that to fail, and so should # croak with a nice message $file->header(); }; # expected error message returned by the # croak in File::header() like($@, qr(Error in reading file header)); ...