Use the Net::NNTP or News::NNTPClient modules, both available from CPAN. This can make tasks like fetching the newsgroup list as simple as
perl -MNews::NNTPClient -e 'print News::NNTPClient->new->list("newsgroups")'