#!/usr/bin/perl use Algorithm::Diff qw(traverse_sequences); use Term::ANSIColor; use strict; use warnings; my @from = split //, shift // 'this is the left string'; my @to = split //, shift // 'this is the right string'; 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";