#!/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;