http://www.perlmonks.org?node_id=940455


in reply to Best way to dynamically use a .pm?

Read use Module and require. PMs can put their subs in any package. PM names just look like packages, but they aren't, and a PM doesn't have to put subs in the package its named after (a good idea for unmaintainable code). PMs are simply text files given to the do EXPR function.

Note, you can write the require and use functions yourself in pure perl.

I think for your case 1 PM per data format, loaded using requires, or put a begin block read the data header and then do a require in the begin block, parse the file outside of the BEGIN block/normal runtime.