my @pfx_keys = qw( category division priority resolved ); my @sfx_keys = qw( customer worker ); for my $key (sort keys %output) { my $val = $output{$key}; my @pfx = map { $val->{$_} } @pfx_keys; my @sfx = map { $val->{$_} } @sfx_keys; my @current = split("\n",$val->{'current'}); my @tis = split("\n",$val->{'tis'}); for my $i (0 .. $#current) { my $line = join(',',$key,@pfx,$current[$i],$tis[$i],@sfx); print "$line\n"; } } #### AUTO,Shelf,deployment,3,YES,CLOSED2/1,200,NO,YES AUTO,Shelf,deployment,3,YES,CLOSED2/2,300,NO,YES AUTO,Shelf,deployment,3,YES,CLOSED2/3,400,NO,YES AUTO,Shelf,deployment,3,YES,CLOSED2/4,200,NO,YES