# File: match2.pl # Title: From the assembling DNA problem # You have 2 strings check if the suffix of s1 == prefix of s2 # In our problem we put s = s1.XX.s2 put XX in the middle as a FENCE # XX is introduced by the programmer. Symbol X should not be to be found in s # then look just at one string s # Reminder $s =~ /(.{$n})/; # put in $1 first n chars # .{$n} - that is repeat .(anything) n times # () means set result in variable $1 # \S = means non-whitespace char # (.{2}) means put in $1 - 2 chars # (.{2,}) put in $1 more than 2 chars # \1 matches text previously matched first # ([\S]{2,})XX\1/ - means # finds first XX, takes longest substring before XX and matches with substring after XX # Find suffix before XX and that matches prefix after XX # Author: Mihaela Malita $s = "ttaaaXXaaaammmmm"; # find suffix aaa equal with prefix aaa in second string $s =~ /(.{2})XX/; # find substring before XX length 2 (find 2 chars before XX) print $1, "\n"; # prints aa $s =~ /(.{2,})XX/; # find substring before XX longer than 2 print $1, "\n"; # prints ttaaa -maxim length {2,} means > 2 $s =~ /(.{3})XX\1/; # look for 3 chars before XX, match is put in \1 print $1, "\n"; # prints aaa print("Finds in $s longest suffix before XX = with prefix after XX:\n"); $s =~ /([\S]{2,})XX\1/; # \1 takes the value of the first match - suffix print $1, "\n"; # prints aaa exit;