#!/usr/bin/env perl use strict; use warnings; my %device_info = ( DEVA => [qw{a b c}], DEVQ => [qw{q r s}], DEVX => [qw{x y z}], ); my $json = [ { read => [ { qw{r u3 s f1 q s4} }, { qw{q s6 r u4 s f2} }, ], dev => 'DEVQ', rep => 'A', }, { read => [ { qw{y u3 z f1 x s4} }, { qw{x s6 y u4 z f2} }, ], dev => 'DEVX', rep => 'B', }, { read => [ { qw{b u3 c f1 a s4} }, { qw{a s6 b u4 c f2} }, ], dev => 'DEVA', rep => 'C', }, ]; for my $report (@$json) { print "Report $report->{rep} - "; my $device = $report->{dev}; print "Device $device\n"; my @order = @{$device_info{$device}}; for my $readings (@{$report->{read}}) { print "\t@{$readings}{@order}\n"; } } #### Report A - Device DEVQ s4 u3 f1 s6 u4 f2 Report B - Device DEVX s4 u3 f1 s6 u4 f2 Report C - Device DEVA s4 u3 f1 s6 u4 f2