my $previous = ; while () { # compare $_ and $previous here $previous = $_; }