First of all, the lack of <code> tags makes your question very unclear, which is probably why you haven't had many responses.
$pattern = LP[SKTAQEHLDN][TA][GN][EDASTV] = 5/6
That makes it a little clearer.
I've been having a bit of a play around with this, and one approach that you could take is to turn each of your alternations into captures, and make them optional. So you'd do something like (L)?, then (P)?, then ([SKTAQEHLDN])?, etc.

If you assign the match(es) directly to an array variable, you'll end up with a six element list where each defined element represents a successful match. Then it's simply a matter of counting the number of defined elements. If you have more than 4, it's a successful overall match.

Here is some sample code to demonstrate what I mean:

#!/usr/bin/perl -wl use strict; while (my $string = <DATA>) { chomp($string); my @matches = $string =~ /(L)?(P)?([SKTAQEHLDN])?([TA])?([GN])?([E +DASTV])?/; my $num_matches; for (@matches) { $num_matches++ if defined($_); } if ($num_matches > 4) { print "$string matches ($num_matches/6)"; } else { print "$string does not match ($num_matches/6)"; } } __DATA__ LPSTEOPRTRYERTRETR HELLO WORLD PERL MONKS
Which prints:
LPSTEOPRTRYERTRETR matches (5/6) HELLO WORLD does not match (2/6) PERL MONKS does not match (2/6)

Note that the above could probably be "golfed" significantly, but I've deliberately kept it verbose to make it obvious what's happening.

Cheers,
Darren :)


In reply to Re: pattern matching tricky one by McDarren
in thread pattern matching tricky one by Anonymous Monk

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.