If there are more lines to follow in your file and you want to automatically detect the end of the pattern without specifying the pattern explicitly, you can use the module String::Similarity, for example:
use strict;
use warnings;
use String::Similarity;
my $string;
$string .= "abc($_) = xyz(".($_-1).");\n" for 1..10;
$string .= "not similar\n";
my @lines = split /\n/, $string;
for (1..$#lines) {
print "\"".$lines[$_-1]."\" == \"".$lines[$_]."\" ? ";
print similarity $lines[$_-1], $lines[$_];
print "\n";
}
gives the following output
"abc(1) = xyz(0);" == "abc(2) = xyz(1);" ? 0.875
"abc(2) = xyz(1);" == "abc(3) = xyz(2);" ? 0.875
"abc(3) = xyz(2);" == "abc(4) = xyz(3);" ? 0.875
"abc(4) = xyz(3);" == "abc(5) = xyz(4);" ? 0.875
"abc(5) = xyz(4);" == "abc(6) = xyz(5);" ? 0.875
"abc(6) = xyz(5);" == "abc(7) = xyz(6);" ? 0.875
"abc(7) = xyz(6);" == "abc(8) = xyz(7);" ? 0.875
"abc(8) = xyz(7);" == "abc(9) = xyz(8);" ? 0.875
"abc(9) = xyz(8);" == "abc(10) = xyz(9);" ? 0.848484848484849
"abc(10) = xyz(9);" == "not similar" ? 0.0714285714285714
|