#!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