use strict; ################## #The Function ################## sub demux { my ($rsrc,$separator)=@_; #a reference to the list of tuples, and the separator my @res; # result my $nbelem=@{[split /$separator/, $$rsrc[0]]}; #this may be a little bit *gruik* to get the number of elements in each tuple... foreach my $n (0.. $nbelem-1){ push @res , [(map { (split /$separator/ )[$n] } @{$rsrc} )]; #that took me ages to figure out :D } return @res; #guess what! } ################### #The Test ################### sub even { #self explanatory return $_ if ($_=int(rand(100)),$_%2==0); return $_+1; } sub odd { #worse :D return &even+1; } my @liste; push @liste, (&odd.",".&even.",".&odd.",".&even.",".&odd.",".&even) foreach(1..10); #create a list of even and odd numbers alternating (so that we understand easily) print "$_\n" foreach (@liste); #print it out print "\n"; my @re= demux(\@liste,","); # it's a kind of magic print "@{$_}\n" foreach(@re); # Yehaaaaww!!