use Symbol qw( gensym ); sub FOO { state $fh = gensym(); $fh } open(FOO, ...)