my @sentences = ( 'This is a sentence', 'This is another sentence', ); my $matches = grep /\bthis is\b/i , @sentences; #### print Start_In_Common( 'This is a sentence', 'This is another sentence' ); sub Start_In_Common { my ($first, $second) = @_; ($first, $second) = ($second, $first) if length $first > length $second; my @word = ( [split /\s+/, $first ], [split /\s+/, $second ] ); my @fragment; for ( 0 .. $#{ $word[0] } ) { if ( $word[0][$_] eq $word[1][$_] ) { push @fragment, $word[1][$_]; } else { return join ' ', @fragment, scalar @fragment; } } }