in reply to How do I append or write to the end of a file?

Best thing would be is to open the file in the append mode ,, Not a fan of the previous answer , for one reason that it will not work :
!/usr/bin/perl use strict; open (FILE, "file") || die "File does not exist\n"; my @file = <FILE>; my $file = @file; close (FILE); open (FILE, ">file") || die "File does not exist\n"; for (my $n = 0; $n <= $file; $n++) { $_ = $file[$n]; print FILE $_; } print "add whatever"; --> should be print FILE "add whatever"; print "here\n"; --> should be print FILE "here\n"; print "to end of txt.\n"; --> should be print FILE "to end of txt.\n"; close (FILE);

Originally posted as a Categorized Answer.