$file = aaa.txt first time file mode open( my $testfile, "+>> $file" ) $!\n"; if ( -z "$testfile" ) ---> checking for empty file { write some o/p data close( $testfile ); #### open( my $testfile, "+>> $file" ) $!\n"; ---- ---- some condition check now adding some other info to the existing file close the file