#! /usr/bin/perl # vim:ts=4 sw=4 sts=4 et nu fdc=3: use strict; use warnings; use Data::Dumper; $Data::Dumper::Sortkeys = 1; # data structure: Hash of Arrays # Device => [ list of vlan IDs ] my %vlan = ( device_1 => [ 1..38 ], device_2 => [ 1..48 ], device_3 => [ 1..24 ], ); # take 10 items of each device sub hash # process items # redo until all sub hashs are empty my %data; do { %data = (); for my $dev ( keys %vlan ) { # skip if no vlan IDs left for current device next if 0 == @{ $vlan{$dev} }; # extract next 10 IDs of current device $data{$dev} = [ splice( @{$vlan{$dev}}, 0, 10 ) ]; } # process extracted data print Dumper( \%data ); } while ( keys %data ); __END__