in reply to how to get cmd prompt output

That's what backticks, aka qx, are for.

defined( my $hostname = `/bin/hostname`) or die "No host";
I've used the absolute path to hostname to remove a possibly insecure dependence on $ENV{PATH}.

After Compline,
Zaxo