#!usr/bin/perl my $FILENAME4 = "organized.txt"; open(DATA2, $FILENAME4); #remove all previous re-organized files my $remove_reorganized = "re-organized.txt"; if (unlink($remove_reorganized) == 1) { print "Existing \"re-organized.txt\" file was removed\n"; } #now make a file for the ouput my $outputfile = "re-organized.txt"; if (! open(POS, ">>$outputfile") ) { print "Cannot open file \"$outputfile\" to write to!!\n\n"; exit; } while (my $organized = ) { #do some re-organizing #sort out the group numbers first my ($first, $second) = split(/^\s{1}/, $organized); $first =~ /(\d+){1}/; my $first_num = $1; #now sort out the other data #create an array to hold the data my @storage = (); my @final_storage = (); my @second = split(/\s+/, $second); foreach my $second_num(@second){ $second_num =~ s/(\w+)/z/g; @storage = $second_num; push (@storage, $1); } push @final_storage, $storage[$_] foreach 0..$#storage; print POS "$first_num @final_storage\n"; }