Here is some half hearted sample code. In this case I assume you have read your lines for each file into @file1_lines and @file2_lines. I also assume you've run chomp on the arrays. This is a reasonable approach if you know your files are a manageable size and you don't mind loading them entirely into memory. In practice I would recommend a while loop to read any file of unknown size whenever possible.

My guess, given your expected output, is that when you see any of the strings in file2 in file1, you would like to delete that string and the rest of the line in file1. I've tried to be extra verbose here in showing this replace, and pushing the results to @output_array.

$replace_pattern is a pattern built from the strings in file2 to match any of those strings to the end of the line. The sample code produces your desired output sample.

my @file1_lines = qw( xxtcgtatccgaggga cgcgcgggggagg jjsjjjjsjjjdtcgtat aaaaaaacccaaan ggtcgtatffaadda gggctggalllslllssdkk ); my @file2_lines = qw( tcgtat gctgga ); my $replace_pattern = join('.*|', @file2_lines) . '.*'; my @output_array; for my $line (@file1_lines) { my $output_line = $line; $output_line =~ s/$replace_pattern//; push @output_array, $output_line; } say for @output_array;

In reply to Re: array matching by Kc12349
in thread array matching by polsum

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.