#!/usr/bin/perl use strict; use warnings; while () { my $cmpline = ; # I always have a pair to compare my ($spanold, $spannew) = spandiffstr ($_, $cmpline); print "$spanold"; print "$spannew"; } sub spandiffstr { my ($old, $new) = @_; my $span = ''; #eventually I'll pass this in as arg my $espan = ''; #ditto my @cold = split //, $old; my @cnew = split //, $new; my $longer = (@cold > @new) ? $#cold : $#cnew; my $subscr; #find first diff in string from front. for (0..$longer) { if ($cold[$_] ne $cnew[$_]) { $subscr = $_; last; } } my $losubscr; #two subscripts because differ len of new and old my $lnsubscr; @cold = reverse @cold; @cnew = reverse @cnew; #we're gonna search these backwards for (0..$longer) { if ($cold[$_] ne $cnew[$_]) { $losubscr = @cold - $_; $lnsubscr = @cnew - $_; last; } } #got pertinent subscripts, now insert span tags substr ($old, $losubscr, 0) = $espan; substr ($new, $lnsubscr, 0) = $espan; substr ($old, $subscr, 0) = $span; substr ($new, $subscr, 0) = $span; return ($old, $new); } __DATA__ I love Perl. I love Your Mom. I love to eat spaghetti. I love to eat spaghetti and meatballs. I love to smell the flowers. I hate to smell the flowers. Stop! That's enough. Not really enough. Blood and Tears are expected. Love and Marriage are exempted. #### I love Perl. I love Your Mom. I love to eat spaghetti. I love to eat spaghetti and meatballs. I love to smell flowers. I hate to smell flowers. Stop! That's enough. Not really enough. Blood and Tears are expected. Love and Marriage are exempted. #### Blood and Tears are expected. Love and Marriage are exempted.