in reply to List manipulation headache
Don't worry about the specific Perl (or whatever) code. If you can't explain the solution in your native language, you can't write the software...