use strict; sub test { my $filename = 'test2.txt'; if (-f $filename) { print "File Exists!"; } else { print "File does not exist"; } } sub openFile { open my $fh, '>>', 'test2.txt'; print "file open!\n"; print $fh "The stuff I wanted to add to the end of the file.\n"; } test(); openFile(); test(); #### $: perl foo.pl File does not exist file open File Exists! $: cat test2.txt The stuff I wanted to add to the end of the file. $: perl foo.pl File Exists! file open File Exists! $: cat test2.txt The stuff I wanted to add to the end of the file. The stuff I wanted to add to the end of the file. $: