in reply to Finding common substrings

Firstly, $a and $b are best avoided as variable names as they are pre-declared for use with the sort function. You could do this task by splitting one string on spaces (assuming your data is always space delimited) to populate a hash and then splitiing the second string and checking if any part of that exists already in the hash.

use strict; use warnings; my $str1 = q{PF01389 6 218 1 255 430.09}; my $str2 = q{PF00691 PF01389}; my %str1Hash = map {$_ => 1} split m{\s+}, $str1; foreach my $possible (split m{\s+}, $str2) { print qq{$possible common\n} if exists $str1Hash{$possible}; }

I hope this is of use.

Cheers,

JohnGG