To understand the script, you'll need to read the code. Start at the top and work through it a few lines at a time. when you get to a section that you don't understand, ask a specific question about that portion.

You can also step through the script using the perl debugger to see it in action.