#! perl -lw use strict; use Data::Dumper; BEGIN{ our %channels; my $channel; while( @ARGV ) { $_ = shift @ARGV; $channel = shift @ARGV and next if m[-channel]; $channels{ $channel }{ $1 } = shift @ARGV and next if m[-([a-z])]; die "Invalid arg '$_'"; } } our %channels; print Dumper \%channels; __DATA__ P:\test>456642 -channel 1 -a 1 -b 1 -c 1 -channel 2 -a 2 -c 2 -channel 3 -b 3 -c 17 $VAR1 = { '1' => { 'c' => '1', 'a' => '1', 'b' => '1' }, '3' => { 'c' => '17', 'b' => '3' }, '2' => { 'c' => '2', 'a' => '2' } };