my ($File, $Line, $Contents, @Lines, $i, $j); $i = 0; $j = 1; $File = "P:\\K\\kmartin\\set1.txt"; # Open file and put it into one long line open (FH, "<$File"); while (defined($Line=)) { chomp $Line; $Contents .= $Line; } close (FH); # Puts words into an array @Lines = split /\W+/, $Contents; while (<@Lines>) { #compare contents on array cell if ($Lines[$i] eq $Lines[$j]) { print "Duplicate word: $Lines[$i]\n"; $i++; $j++; } #If not equal, increment counters else { $i++; $j++; } }