in reply to smart solution

Besides a single >, the thing that the code does in the SERVICE_APPLICATION_EXECUTION_COMPONENT and WEB_APPLICATION_EXECUTION_COMPONENT are identical (as far as I can see). Ensure that the > is really needed there and consider merging the two blocks.

Having the if($os eq 'unx') inside foreach blocks is not a good idea, since the condition is loop-invariant, which means that the outcome of the check inside the ifs won't change, depending on the values of the iterator (foreach). It should be rewritten as:

if(...) { foreach ... (...) { ... } }

And again, the two blocks checking for UNX and WNT are nearly identical. See if you can merge them. Redundant redundant code is redundant redundant is redundant.