package Devel::Count;
sub DB::DB { ++$count }
END { print STDERR "Total statements: $count\n" }
Now perl -d:Count anyprogram.pl prints out:
Total statements: 286