Here's an example. You assign a reference to your own subroutine to the CORE::GLOBAL namespace for the function in question within a BEGIN block. In this case, the custom open() will only accept the 3-arg form of open.
use warnings;
use strict;
BEGIN {
*CORE::GLOBAL::open = sub (*;$@) {
print "in my open...\n";
# the following line calls the built-in open() function
# directly with the params your sub received
CORE::open($_[0], $_[1], $_[2]);
}
};
open my $fh, '<', 'blah' or die $!;
print <$fh>;
Output:
in my open...
file contents
|