use Modern::Perl; use Data::Dumper; my $text= join '', ; my %customers; $customers{$_}++ for $text =~ m/{(.*?)}/g; say Dumper(\%customers); __DATA__ AB1\tA{Daniel Wright}\sA{Jack Smith}\sB{Jane Goodwin} QW1\tA{Samantha Patton}\sC{Timothy Eeckles} AR2\tA{Jane Goodwin} #### $VAR1 = { 'Jane Goodwin' => 2, 'Daniel Wright' => 1, 'Timothy Eeckles' => 1, 'Jack Smith' => 1, 'Samantha Patton' => 1 };