You can run the bash shell test program on the remote machine. It works just like the Perl test operators and ssh will return its return status.
unless (system('ssh', $host, 'test -s $file') == 0) {
You will need to be careful checking the return status of system because 0 is true and anything else is false. And -s checks if the file exists and has non-zero size.
Also, there is no print command; the shell equivalent is echo. You don't need to touch the file first; changing it will update the modtime. Do you really want to append to the file? It either doesn't exist or is zero size so you can use '>' to overwrite the file. I find that especially with ssh, it is better to use the array form of ssh because it makes explicit what is the remote command and you don't have to worry about quoting.
system('ssh', $host, "echo $product > $file");
Even better would be to use the power of the shell and dothe entire operation on the remote machine with a single ssh call.
system('ssh', $host, "if [ ! -s $file ]; then echo $product > $file; f
+i");
|