Because when the subroutine finishes the filehandle also closes. Please also check that this in your code open FILE4,"$_[3]" || die "could not open $_[3]"; which has no ">" like the others.bart you are right, I missed that.Simply using strict and warnings would have indicated the problems.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me