my $file = 'file.txt'; open my $wfh, '+>', $file or die "Couldn't open file $file: $!"; print $wfh join "\n", @output; close $wfh;