#!/usr/bin/perl # https://perlmonks.org/?node_id=1221960 use strict; use warnings; use Data::Dumper; open my $fh, '<', \<} =~ /^TG:\s(VIN:\d+)\ntype:\s(.*)/gm; print Dumper \%hash; #### $VAR1 = { 'VIN:1000001' => 'a very special type of car', 'VIN:1000002' => 'a very special type of boat', 'VIN:1000000' => 'a very special type of plane' };