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}