Your issue may be related to use strict;. @h2{ @selected } = @h1{ @selected }; uses hash slices to copy values from one hash to another. However, if you simply affix a my, perl will interpret that as a malformed array declaration. If this sounds like your issue, precede the line in question with the statement my %h2;.