use strict; use warnings; use Data::Dumper; my $result = {}; local $/ = "\n\n"; while(my $block = ){ chomp $block; my %info = map{ split /\s*:\s*/, $_, 2 }split /\n/, $block; my $oid = $info{SamAccountName}; $result->{$oid} = \%info; } print Dumper $result; __DATA__ SamAccountName : U011004 LastLogonDate : 20.06.2016 15:01:10 ExpiryDate : 19.12.2016 13:58:05 PasswordLastSet : 20.06.2016 14:58:05 mail : J.W@dbx.com SamAccountName : U011001 LastLogonDate : 25.05.2016 09:53:51 ExpiryDate : 23.11.2016 08:53:28 PasswordLastSet : 25.05.2016 09:53:28 mail : MM.AA@yxz.de