name=Document1.doc type=Word author=aAuthor name=Document1.doc type=Excel author=bAuthor name=Document1.doc type=Text author=cAuthor name=Document1.doc type=Excel author=dAuthor name=Document1.doc type=Word author=eAuthor #### name=Document1.doc type=Excel author=bAuthor name=Document1.doc type=Excel author=dAuthor name=Document1.doc type=Text author=cAuthor name=Document1.doc type=Word author=aAuthor name=Document1.doc type=Word author=eAuthor #### #$field is the position of the element (sort key) in the #line open INPUT , $input || die $input.$! ; while () { @fields = split(" ",$_) ; push @{$hash{$fields[$field]}}, $_ ; $hash_keys{$fields[$field]} = $fields[$field] unless exists $hash_keys{$fields[1]} ; } for $element (sort keys %hash_keys) { open OUTPUT, ">>$output" || $output.$! ; print OUTPUT @{$hash{$element}} ; close OUTPUT ; } close INPUT ;