use strict; use warnings; use Data::Dumper; my $kml = do { local $/, }; my %hash; while ($kml =~ m/((?:(?!).)*)<\/name>\s*((?:(?:(?!).)*)<\/coordinates>)/gs){ $hash{$1} = $2; } print Dumper \%hash; output: ------- $VAR1 = { 'One more' => '56,78,0', 'This is the title' => '12,34,0' };