This has nothing to do with whether you use 'my' or not. You call $dbh->prepare whenever the subroutine is run. (It is possible that the method prepare checks if it is called with the same parameters and does nothing in that case, check your module documentation)