... open (my $fh1, "+>", $output1) or die "Cannot open file '$output1': $!"; ... seek $fh1, 0, 0; while (<$fh1>) { ...