in reply to Finding common substrings
$a = 'PF01389 6 218 1 255 430.09'; $b = 'PF00691 PF01389'; $_ = " $a \n $b "; # combine strings for one regex print "$_\n" for / (\S+) (?=.*\n.* \1 )/g; [download]