#!perl -w use strict; use warnings; use subs qw(open); use Errno qw(EPIPE); sub open { $! = EPIPE; warn "open faked"; return 0; } Test::subs(); exit(0); package Test; sub subs { my $string = "hello world"; local *STDIN; open(STDIN, '<', \$string) or die "open failed: $!"; binmode STDIN; while(<>) { print; } } 1 #### local *IO::File::open = sub {.....} #### #!perl -w use warnings; use Errno qw(EPIPE); use lib qw(.); eval "use Test;"; BEGIN { *{main::open} = sub { $! = EPIPE; warn "open faked"; return 0; }; } Test::subs(); exit(0); #### package Test; sub subs { my $string = "hello world"; local *STDIN; open(STDIN, '<', \$string) or die "open failed: $!"; binmode STDIN; while(<>) { print; } } 1