in reply to volatile memory?

Could you post a short, but complete, program that exhibits the behaviour? For instance, your code fragment show $buffer to be scoped outside of the while loop, while the code doesn't show sub new_value or sub mytestfunc. Or even my_condition. If any of those functions modifies $buffer, you have your answer.