in reply to Detect socket

You could try calling  getsockopt( $mysocket, getprotobyname( 'tcp' ), TCP_NODELAY ).

On my OS I get an error that tells me if the file descriptor provided is not a socket:

getsockopt( STDOUT, getprotobyname( 'tcp' ), TCP_NODELAY ) or warn "?$! : $^E";; ?Unknown error : An operation was attempted on something that is not +a socket

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy