#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11127688 use warnings; use Algorithm::Diff qw(traverse_sequences); use Term::ANSIColor; while( ) { my @from = split /(\s+)/; my @to = split /(\s+)/, ; traverse_sequences( \@from, \@to, { MATCH => sub {print $from[shift()]}, DISCARD_A => sub {print color('red'), $from[shift()], color 'reset'}, DISCARD_B => sub {print color('green'), $to[pop()], color 'reset'}, } ); print "\n\n"; } __DATA__ A few moments will suffice to commit it to memory; yet the period which it covers, commencing more than twenty-five centuries ago, reaches on from that far-distant point past the rise and fall of kingdoms, past the setting up and overthrow of empires, past cycles and ages, past our own day, over into the eternal state. A few moments will suffice to commit it to memory, yet the period which it covers, beginning more than twenty-five centuries ago, reaches from that far-distant point past the rise and fall of kingdoms, past the setting up and overthrow of empires, past cycles and ages, past our own day, to the eternal state. Now opens one of the sublimest chapters of human history. Now opens one of the most comprehensive of the histories of world empires. With what interest, as well as astonishment, must the king have listened, as he was informed by the prophet that he, or rather his kingdom, the king being here put for his kingdom (see the following verse), was the golden head of the magnificent image which he had seen. With what interest and astonishment must the king have listened as he was informed by the prophet that his kingdom was the golden head of the magnificent image.