You need to make that "BEGIN {" not "{" to ensure that the initialization for $count happens once and only once. For example, if that code were in some sort of outer loop, you'd get $count cannot stay shared (I think), and if you had an initializer for $count, but that block were at the end of the file, "manipulate_count" would be called before $count had been initialized.