BEGIN { *CORE::GLOBAL::open = sub (*;$@) { ($package, $filename, $line) = caller(); print "LOGGING: intercepted `open` call from ( package: '$package', file: '$filename', line: '$line' ) with args: '??', ".join(", ",map{ "'$_'" } @_) . "\n"; if(defined($_[0])) { use Symbol qw(); my $handle = Symbol::qualify($_[0],(caller)[0]); no strict 'refs'; if(@_ == 1) { return CORE::open($handle); } elsif(@_ == 2) { return CORE::open($handle, $_[1]); } else { return CORE::open($handle, $_[1], @_[2..$#_]); } } else { if(@_ == 1) { return CORE::open($_[0]); } elsif(@_ == 2) { return CORE::open($_[0], $_[1]); } else { return CORE::open($_[0], $_[1], @_[2..$#_]); } } }; } open(my $fh, "<", ".bashrc") or die "unable to use hacked up open function: $!"; my $top = <$fh>; print $top; #### LOGGING: intercepted `open` call from ( package: 'main', file: './coreover.pl', line: '34' ) with args: '??', '', '<', '.bashrc' # ~/.bashrc: executed by bash(1) for non-login shells.