#!/usr/bin/perl # rcwords.pl: print immediately adjacent repeated words once from input, # even if they are repeated more than once, # and print out these words along with the line number(s) that they appeared. use English; use diagnostics; $prevword = ''; $n = 0; while ($line = <>) { $n = $n + 1; $line =~ s/[[:punct:]]/ /g; $line = lc $line; @words = split /[[:space:]]+/, $line; foreach $word (@words) { if ($word ne '') { if ($word eq $prevword) { print " $n $word\n"; } $prevword = $word; } } }