in reply to Preserve original text formatting.

#!/usr/bin/perl # http://perlmonks.org/?node_id=1141535 use strict; use warnings; my $numwords = 40; $_ = "To be or not to be.\n"; # or read from file... my @previous; # holds the $numwords previous words s/(\w+)/ my $match = grep lc $1 eq lc, @previous; push @previous, $1; @previous > $numwords and shift @previous; $match ? "*$1*" : $1 /ge; print;

Replies are listed 'Best First'.
Re^2: Preserve original text formatting.
by larsb (Novice) on Sep 10, 2015 at 16:11 UTC
    Thanks, that regex really opened up my eyes to what can be accomplished.

      Aye ... and the Perl language will never cease in doing just-exactly that.   If you ever pondered, “so, what is all the Fuss about?,” well, “here it is.”