/tmp/foo.conf: sub f { print __PACKAGE__, "\n" } 1; main script: package P1; do '/tmp/foo.conf'; package P2; do '/tmp/foo.conf'; P1::f(); P2::f(); which outputs: P1 P2