in reply to Question with Dynamically Creating arrays.

Perl’s concept of “references” can be put to very good use in situations like these, and Perl makes it very easy to do.   (In fact, it often happens implicitly.)

Once you have constructed a single memory-variable to contain a piece of data, you can add references to it into any number of other hashes or lists ... thereby giving yourself the ability to quickly find the value using any of these means.   In the memory of the computer, there is only one instance of the value.   That instance contains a “reference count” (managed entirely by Perl), which says how many references to it have been created.   The data will not be garbage collected until that reference count becomes zero.

In your example, it seems that when presented with a variable having a key such as xx,yy,zz, you wish to be able to find the value using any one of those subkeys.   Two approaches immediately come to mind:

  1. Just store the value in a hash under its key, then use the grep function against the list of keys which contain the substring you are looking for.   Search all of the keys that you find.
  2. Create a single record containing the key, then break down the key into its constituent parts and add a reference to the record under each part.   (The data structure in this case would be a hash pointing to an array of references.)