sub test_foo { my $temp; $temp = $^W; # save warning flag status $^W=0; # ignore "function is redefined" warning local *module::bar=\&stub_for_bar; $^W = $temp; # restore warnings # test code for module::foo() goes here }