#!/usr/bin/perl #This script matches words that are repeated within words and marks them and prints out the original text with repeated words marked. use strict; use warnings; print "Enter the name of the file to check: "; my $inputfile = <>; #Define how many words between matching a repeat. my $numwords = 40; open(TEXTFILE, $inputfile); my @importedtextfile = ; close(TEXTFILE); my $counter = 0; my @words; #Split the sentences imported. foreach (@importedtextfile) { my @tempsplit = split(/\s+/, $_); foreach(@tempsplit) { push @words, $_; } } my @filteredlist = @words; my $wordslength = scalar(@words); $counter = 0; foreach(@words) { my $i = 0; my $currentword = $_; $currentword =~ s/[\,\.]//g; #Start counting one word "right" of the one you are trying to match. my $startposition = $counter + 1; #Check words and make sure you don't check empty strings in array. while ($i < $numwords and $counter + $i < $wordslength) { if ($counter + $i + 1 < $wordslength) { my $matchword = $words[$startposition]; $matchword =~ s/[\,\.]//g; #Match and replace in new array. if ($currentword =~ /\b$matchword\b/i) { $filteredlist[$startposition] = "*".$words[$startposition]."*"; } } ++$startposition; ++$i; } ++$counter; } my $printedlist = join(" ", @filteredlist); print "$printedlist\n";