in reply to opening a file for printing
You need a heuristic, which as Dominus puts it "is a fancy way of saying that it doesn't work".
File::MimeInfo::Magic might do what you want.