in reply to Extracting string based on comparison to second string?

What have you tried? What didn't work? See How do I post a question effectively?. In general, we can be more helpful when we can see where you've had difficulty and can gauge your experience.

As I understand your spec, you can use regular expressions to locate where in your masks your codes fall and then use the special variables @- and @+ along with substr to extract the appropriate characters. Something like:

#!/usr/bin/perl use strict; use warnings; my @searches = qw( .LLL LLLL .RRR RRRR ); my @file = <DATA>; chomp @file; for my $search (@searches) { for my $line (@file) { my ($string, $mask) = split /\s+/, $line, 2; my @matches; while ($mask =~ /\Q$search\E/g) { my $start = $-[0]; my $end = $+[0]; push @matches, substr $string, $start, $end - $start; } local $" = ","; print "$line\t\t@matches\n"; } } __DATA__ THAETURQU .LLL..RRR JURYATAUTIOPW .LLL...LL.RRR TURIWOWQNQQUTYRIOPWMNHF L..L..LLLL.LL.R..L.LLLL

Note I used \Q and \E to escape metacharacters since . has special meaning in regular expressions. See perlretut on info on how to build regular expressions.