# copy2.pl use strict; my $test = system('perl', 'write.pl'); my $file1 = 'foo.txt'; while(1) { last if -e $file1 && ! qx/lsof $file1/; } my $status = system("cp $file1 file2");