my $filename = "anything.ldif"; unless (open (LDIF, $filename)) { die "Error: couldn't read from '$filename': $!\n"; } else { my %seenObjects = (); local $/ = "\n\n"; # read objects, not lines while () { # $_ has one object now chomp($_); s/\n //g; # kill continuation lines if ($seenObjects{$_}++) { # object already seen... write to another filehandle print OUTFILE "$_\n\n"; } # if } # while close (LDIF); } # else