use strict; use warnings; use Data::Dumper; my %temp=(); my %main_struc=(); my $match='Person2'; while (my $line = ) { chomp $line; my @fields = split ("," , $line,2); my @temp=split(',',$fields[1]); foreach my $data (@temp){ my($key,$value)=split('=',$data); $key =~ s/^\s+//; $key =~ s/\s+$//; $main_struc{$fields[0]}{$key}=$value } } print Dumper \%main_struc; print "@{$main_struc{$match}}{'Name','Age','Gender'}"