use Socket qw(SOL_SOCKET SO_LINGER); setsockopt($socket, SOL_SOCKET, SO_LINGER, pack("sll",1,0,0)) or die( "setsockopt: $!" );