If you take a look at the Configuration and Capability Methods section of the Win32::SerialPort documentation, there are subsections on "Asynchronous I/O" and "Timeouts" (just before the Exports section). You'll want to check out write_const_time and write_char_time. I think those sections will help you with the timeout stuff.
I mean I want to stop the write command if the other side is empty. Now if i am trying the write command and the other side is inactive or I just plug out the cable the software freezes out.
Perhaps I'm misunderstanding what you're trying to accomplish, but it sounds like you're also needing/wanting some method to detect that the connection is broken (i.e. the serial device is off or disconnected) and to gracefully handle this without locking up your script. You can easily check the success of opening a new connection, but I'm not sure that I would know how to determine that the serial device has dropped the connection. It's been a few years since I wrote something using Win32::SerialPort and I don't think that I had thought about checking for this scenario.