I don't know of any such tool, but if I had to try to create one, I'd probably do something like this:
- Break the suspect file up into chunks
- Use Parse::Perl to try to parse each chunk
- If the ratio of 'good chunks'/'chunks' meets your threshold, assume it's valid.
There are quite a few problems in this approach. Choosing a threshold will be difficult, and the value may be too sensitive to the files you use to test it. If there are enough templates or strings in the code, you'll likely reject the file. If you lower the acceptance ratio to pass those, then you may pass quite a bit of junk. Breaking the file into chunks is also a challenge--if you break them apart poorly, you'll get too many parse failures, so how will you split it up--will you split on newlines? semicolons? curly brackets?
Have you thought about recognizing various patterns of junk and rejecting files based on those patterns? It might be easier.
When your only tool is a hammer, all problems look like your thumb.