in reply to checking if file is empty or not

You can use stat 'Filemane' this returns a 13 element list giving the statistics
for the file "Filename" so
@res = stat "file_to_stat"; print qq($res[7]\n);
will return the size of the file in bytes, the other elements of the list are as follows
dev - Device number ino - Inode number mode - File node (type and permissions) nlink - No of hard links uid - File owner gid - Group Id rdev - Device identifier size - size in bytes atime - access time mtime - modified time ctime - Inode change time blksize - Prefered block size blocks - actual number of blocks allocated
Note: Not all fields are supported bt all OSs.
Hope this is of help