I do it in another approach. I won't put everything in single line of regex, it would make the code hard to debug in future and limit the capability to expand if needed.

print "Content-Type: text/html; charset=utf-8\n\n"; my (@arr1) = ( "ldt", "b05dcc00", "mny", "b05can03*n0b5", "b05mdd04*n9c9" ); my (@arr2) = ( "/* To start: b05afn10ud0b0 */", "/* To start: b05dcc00ud0c0 */", "/* To start: b05ldt10ud0e0 */", "/* To start: b05dcc10ud0i0 */", "/* To start: b05afn10ud0m0 */", "/* To start: b05afn10ud0s0 */", "/* To start: b05mny00ud0b5 */", "/* To start: b05mny00ud0d3 */", "/* To start: b05mdd04un9c9 */", "/* To start: b05ahn00ud0j5 */", "/* To start: b05mny00ud0m7 */", "/* To start: b05can03un0b0 */", "/* To start: b05can03un0b5 */ " ); foreach my $line1 (@arr1) { chomp($line1); # clear \n if data is from file $line1 =~ s/^\s+//; # remove leading whitespace $line1 =~ s/\s+$//; # remove trailing whitespace if ($line1 ne "") # proceed only if something in $line1 { print "Search [$line1]....<br>"; foreach my $line2 (@arr2) { chomp($line2); # clear \n if data is from file $line2 =~ s/^\s+//; # remove leading whitespace $line2 =~ s/\s+$//; # remove trailing whitespace my ($data) = ($line2 =~ m/\/\*(.*)\*\//si); # extract anything w +ithin /* */ my ($name, $value) = split( /\:/, $data ); # split separator cha +r : $value =~ s/^\s+//; # remove leading whitespace $value =~ s/\s+$//; # remove trailing whitespace if ($line1 =~ /\*/) # check if $line1 contain special char { my ($part1, $part2) = split( /\*/, $line1 ); if ($value =~ m/$part1(.*)$part2/i) # /i make it incase sensit +ive { print "match $line2<br>"; } } else { if ($value =~ m/$line1/i) { print "match $line2<br>"; } } } # // foreach $line2 print "<br>"; # print empty line } } # // foreach $line1

Output result

Search [ldt].... match /* To start: b05ldt10ud0e0 */ Search [b05dcc00].... match /* To start: b05dcc00ud0c0 */ Search [mny].... match /* To start: b05mny00ud0b5 */ match /* To start: b05mny00ud0d3 */ match /* To start: b05mny00ud0m7 */ Search [b05can03*n0b5].... match /* To start: b05can03un0b5 */ Search [b05mdd04*n9c9].... match /* To start: b05mdd04un9c9 */

In reply to Re: How to match specific character in a string? by hankcoder
in thread How to match specific character in a string? by WWq

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.