#!perl -w use strict; use Data::Dumper; my @fields = qw/attr-name mtype attr-id default-id/; chomp(my @data = ); my (@parsed_data, %temp_hash, %data_hash); while (@data >= @fields) { @temp_hash{@fields} = splice @data, 0, @fields; push @parsed_data, { %temp_hash }; } for (@parsed_data) { if ($_->{mtype}) { $data_hash{$_->{'mtype'}} = { VALUE => $_->{'attr-id'}, TYPE => 'attr-id' }; } else { $data_hash{$_->{'default-id'}} = { VALUE => $_->{'attr-name'}, TYPE => 'attr-name' }; } } print Dumper \%data_hash; __DATA__ model_name 0x234567 0x654321 0x654321 security_string 0x123456