#!/bin/perl -w use strict; # original code sub1(); sub2(); sub1( "foo", "bar"); sub1( "baz"); sub2( "toto", "tata"); sub sub1 { print "this is sub1 running ", join( ', ', @_), "\n"; } sub sub2 { print "this is sub2 running ", join( ', ', @_), "\n"; } # add this to your code my %function; BEGIN {use vars qw( $AUTOLOAD); # grab the function references foreach (keys %::) { # process only functions! if( defined &{$::{$_}}) { next if( $_ eq 'AUTOLOAD'); # leve this one alone $function{"main::$_"}= \&{$::{$_}}; # store the reference undef $::{$_}; # remove the function from the symbol table } } } sub AUTOLOAD { print "AUTOLOAD running $AUTOLOAD\n"; $function{$AUTOLOAD}->(@_); # call the stored function }