#! /usr/bin/perl use strict; use warnings; my %hash; while ( my $line = ) { my ( $ip, @names ) = map { defined $_ ? $_ : () } split /\s+/, $line; for my $name ( @names ) { $hash{$ip}->{$name} = 1; } } # Ausgabe; die sort-Anweisungen können/sollten noch verfeinert werden for my $ip ( sort keys %hash ) { print "$ip\t", join( ' ', reverse sort keys %{$hash{$ip}} ), "\n" } __DATA__ x.x.x.1 host1.de x.x.x.1 host1.de x.x.x.1 host1.de x.x.x.1 host1.de host1 x.x.x.2 host2 host2.de x.x.x.2 host2 host2.de x.x.x.2 host2.de host2 x.x.x.2 host2.de x.x.x.2 host2