in reply to file command replacement (showing the type of a file with perl)

Usually, the file command relies on the "magic" bytes at the start of a file. Usually these signatures are stored in a file named /etc/magic. There are modules that either include such a database or can reuse such a file. Most are found by Magic (resp. MMagic for File::MMagic).