use Symbol; sub Counter ($) { local $/ = "\n"; my $fh = gensym(); open $fh, "+< $_[0]" or open $fh, "> $_[0]" or return undef; # ... }