use strict; use warnings; use Data::Dumper; my (%coords, @keys, @p, $data, $key, $points, $i); $data = join '', ; while ($data =~ /geometry (\w+).*?point \[(.*?)\]/gs) { $key = $1; $points = $2; @p = $points =~ /(-?\d+\.\d+)/g; my @points; for ($i = 0; $i < $#p; $i += 3) { push @points, [$p[$i], $p[$i+1], $p[$i+2]]; } $coords{$key} = \@points; push @keys, $key; } print Dumper(\@keys, \%coords); __DATA__ geometry IndexedFaceSet { coord Coordinate { point [ 265.185 -166.225 -510.375, 264.529 -166.901 -513.43, 269.321 -166.425 -510.918, 271.021 -166.956 -513.279, 271.223 -167.21 -514.637, 272.77 -166.984 -514.019, 270.767 -167.555 -516.859, 268.668 -167.344 -515.143, 272.884 -167.285 -515.945, 266.267 -167.539 -516.835, 267.193 -167.766 -518.544, 272.686 -167.438 -517.418, 269.214 -167.83 -519.399, 274.761 -166.996 -515.928, 275.801 -166.946 -519.035, 264.372 -167.451 -517.076, 266.21 -167.785 -519.148, 263.801 -167.367 -516.587, 269.266 -167.919 -521.463, 271.322 -167.821 -522.477, 266.656 -168.197 -528.597, 269.644 -168.342 -527.906, 267.007 -167.981 -524.961, 264.07 -167.493 -517.639, 263.244 -167.65 -520.707, 267.726 -167.91 -521.09, 264.468 -167.739 -523.493] }