Using a state variable doesn't seem appropriate here. What the right thing to do here depends on "whatever". If "whatever" is the same all the time, and the value of the variable doesn't change, moving it outside of the loop is the right thing to do. Otherwise, it should be left as is. It's a common case, and perl actually optimizes this - from a language POV, you get a new variable each time. Internally, structures are reused if possible.