libpcap is not relevant to this issue. Even if you grab those packet using libpcap, the header info of those packets would not indicate from which process (OS entity) those packets are emitted. The network layer (compare to OS layer) does not care those processes (OS entity), and does not know those processes (OS entity), and what it cares is from which network entity those packets come.
The info you want is not held by the network layer, but the OS layer.
There is actually no secret how netstat gets those info, and all those data are stored in various system data structures. Netstat just presents those info in an easy to read format.
I don’t know whether there is a Perl module to access those data structures. If not, you can always IPC them from netstat. If you want, do it in embedded c, and maybe make it into a CPAN module.
Comment on Re: Relating AF_INET sockets to processes using Perl