my $old_key = ""; while (<>) { my $key = (split /;/, $_)[2] next if $key eq $old_key; # ... }