Perl script that did not save my life, though helped :-)