(Special) TG: VIN:1000000 type: a very special type of plane (Special) TG: VIN:1000001 type: a very special type of car (Special) TG: VIN:1000002 type: a very special type of boat this repeats many times.. #### #!/usr/bin/perl use strict; use warnings; my $textfile = 'file.txt'; open(TEXT, '<', $textfile) or die $!; my %hash; local $/="(Special)"; while(){ if ($_ =~ /TG:\s(VIN:\d+)\ntype:\s(.+)\n/){ my $keys = $1; my $values = $2; $hash{$keys} = $values; } }