in reply to Encapsulate function and variables

- now I would like to load this file so that its content is encapsulated either in a hash table or in an object. E.g. in file main.pl, I would like to use a function such as capsule that would create such object:

Smells strongly like an XY problem, but you can require your file. Then if its code is within an own package, the latter's stash will be filled with variables and functions. (If you want -and you have to- stay under strict, then use our for the declarations.) Then you can map (perhaps by means of an actual map) that stash into a generic hash. Very clumsy and no reason why one would want to do that, if you ask me, but certainly doable. If you want to have object access, instead, it's enough that you enclose again the code of your file in a package declaration and that obj is blessed into that package. Just very few lines of code to add. Of course this won't also make for automatic access to $obj->text out of a bare $text package variable, but if you really really want that you will need to implement you accessor creating logic mangling the symbol table: again, no really good reason for doing so that I can imagine of.