since your code snippet doesn't show that you need to actually know what the differences are, just that the files aren't the same, what you're looking for is File::Compare (part of the standard distro, i believe). in a similar vein, you could continue to use an external command and switch to cmp.
use File::Compare;
if (compare $file1, $file2)
{
#fail
}
this was discussed earlier in Comparing two files (and a few other times).
if you do need the differences, do a Super Search for Algorithm::Diff (it has been discussed about half a dozen times).