use warnings; use strict; open my $fh1, '<', 'first_file.txt' or die $!; open my $fh2, '<', 'second_file.txt' or die $!; while ( my $s1 = <$fh1> ) { chomp $s1; chomp( my $s2 = <$fh2> ); ( $s1 ^ $s2 ) =~ /[^\x00]/; substr( $s2, $-[0], 0 ) = '+' if defined $-[0]; print $s2, "\n"; } close $fh2; close $fh1;