#!perl use strict; use warnings; use Data::Dump qw/pp dd/; my %hash; local $/="(Special)"; while(){ if ($_ =~ /TG:\s(VIN:\d+)\ntype:\s(.+)\n/){ my $keys = $1; my $values = $2; $hash{$keys} = $values; } } pp \%hash; __DATA__ (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.. #### { "VIN:1000000" => "a very special type of plane", "VIN:1000001" => "a very special type of car", "VIN:1000002" => "a very special type of boat", }