in reply to could not open c

You might want to try printing the contents of $compare, $querry and $library to STDERR before the call to system. That might help tracking down the bug.

Meanwhile, you should also consider adding use strict and use warnings to your code.