"fast and efficient" means, of course, Benchmark, which I'll leave up to you. Also, I'm not quite sure exactly how many is a "whole load". At some point this (or anything else, for that matter, everything has a breaking point) will fail.

#!/usr/bin/perl # http://perlmonks.org/?node_id=1200434 use strict; use warnings; use re 'eval'; my $patterns = <<'END'; ^\d{2}.\d{2}.\d{2}$ date ^\d{2}.\d{2}.\d{4}$ date ^[A-Z]{2}\d{9}[A-Z]{2}$ Royal Mail Track & Trace code ^\d{16}$ visa card ^\d{13}$ EAN-13 barcode END my $regex; sub patternidentification { if( not defined $regex ) { ##################### build a single regex just once my $all = join '|', map { /^(\S+)\s++(.+)/ ? "(?:$1(?{'$2'}))" : die "bad pattern $_ +" } split /\n/, $patterns; $regex = qr/$all/; } return /$regex/ ? $^R : "unknown"; } ##################### then try all matches while(<DATA>) { chomp; my $answer = patternidentification($_); print "$_ is a $answer\n"; } __DATA__ 12 12 17 09 30 2O17 09 30 2017 09 30 12017 123123123123123 1231231231231231 12312312312312312 456456456456 4564564564567 45645645645678 QW123456789WQ

Outputs:

12 12 17 is a date 09 30 2O17 is a unknown 09 30 2017 is a date 09 30 12017 is a unknown 123123123123123 is a unknown 1231231231231231 is a visa card 12312312312312312 is a unknown 456456456456 is a unknown 4564564564567 is a EAN-13 barcode 45645645645678 is a unknown QW123456789WQ is a Royal Mail Track & Trace code

In reply to Re: Pattern Identification by tybalt89
in thread Pattern Identification by WhiteTraveller

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.