in reply to checking if file is empty or not

if (-s $filename) { # The file is not empty }
For more handy file-tests type perldoc perlfunc and search for "test". (For most people that means type "/test" and hit return.)