if (...){ open FH, '>', $file or die $!; } ... if (...){ print FH ...; } ... if (...){ print FH ...; }