You are correct in assuming the while statement is to force output order. This part of the function was taken from the function that actually runs commands on the remote servers. When multiple lines of output are returned simultaneously we want the output to be grouped together instead of intertwined.
I've never used event-based sockets for anything as I'm still relatively new to the programming in general. Any suggestions on where to get started would be appreciated.
I should clarify the CPAN modules statement. Generally I can use anything from CPAN that is already prepackaged in an rpm for CENTOS7/RHEL7 and is in their default repositories. I can also grab modules that can be easily packaged using cpanspec. This tool is to be used internally by teams I support and other teams. Corporate policy forbids quite a few of these teams from having CPAN access so I'm limiting what I can use based on that. If it is a module with very little dependencies I'll consider it. Thanks for your input so far!