#!/usr/bin/perl use strict; use warnings; my @searches = qw( .LLL LLLL .RRR RRRR ); my @file = ; 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