In further review the stand alone script performs the function and the script windows exits after the " sleep 5; " function in the larger program the sub routine does not close down as the main program stays on to perform other functions. I need the " sub stopservices " to exit. In that case a while loop would be needed? Or should I head in a different direction? Thoughts?
It was a simple fix it seems $chan->blocking(0); was keeping the script from properly executing a command. Thanks for the input it made me look closer at the code in depth instead of just surface.