my %default_fields =( desired_temp =>4, desired_volume=>qw[/1 2 3 4 5/], desired_mark=>100 ); my @required_fields=qw/location/; my @fields =(keys %default_fields,@required_fields); #I don't quite get what the part keys %default_fields) .. I # know it put and expand everything into the @fields array sub new { my ($class,%args)=@_; foreach (@required_fiels) { #what does exists($args{$_}}means\? exists($args{$_}) or croak('required fieds $_ omitted"); } %args = (%default_fields,%args); #either set to defaults or new values @this{@fields} = @args{@fields}; #this create a this array of array and set the contents to args return bless(\%this,$class); }