Thanks, and ditto to busunsl. That's certainly solved the problem - I can write my script now, and have re-learnt the ever valuable lesson that time spent researching CPAN is rarely time wasted. But I'd still be very interested if anyone can shed light on why my own attempt didn't work. Is the while loop not restarting? And if so why not?