That doesn't exactly solve the stated problem, does it? As I read it, the OP only wants those lines that only appear one time in the input. What you've given is a way to display a given line from the input at most one time.
Here's a solution (untested, so there's probably boundary problems) that only needs to keep at most 3 lines in memory under the constraint that the lines are already sorted.
#!/usr/bin/perl
use strict; use warnings;
my ($p1, $p2);
while(<DATA>) {
next unless $p1 and $p2;
if ($p2 eq $p1) {$p2 = $p1 = undef; redo; }
if ($p2 ne $p1) { print $p2; next; }
} continue { $p2 = $p1; $p1 = $_; }
__DATA__
a1a
a1a
b1b
c1c
c1c
d1d
d1d
e1e
f1f
g1g
g1g
h1h
h1h
i1i
j1j
k1k
k1k
k1k
|