#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11160609 use warnings; use List::AllUtils qw( pairwise bundle_by ); my @keys = split /, /, 'Pressure, Geop Height, Temperature, Dew Point, Humidity, Wind Direction, Wind Speed MS, Wind UMS, Wind VMS, Precipitation Amount, Total Cloud Cover, Low Cloud Cover, Medium Cloud Cover, High Cloud Cover, Radiation Global, Radiation Global Accumulation, Radiation Net Surface LW Accumulation, Radiation Net Surface SW Accumulation, Radiation SW Accumulation, Visibility, Wind Gusts'; my @datasets = bundle_by { +{ pairwise { $a, $b } @keys, @_ } } 21, split ' ', getdata(); use Data::Dump 'dd'; dd @datasets[0 .. 2]; sub getdata { return '1016.1 7.7 20.6 13.8 72.9 215.0 6.64 3.94 5.33 0.0 31.3 31.3 0.0 0.0 ... 10727690.0 38242.3 10.8'; }