i don't know of any existing modules, but it is an interesting question so i gave it a shot (rough draft!):
use strict; use warnings; use Data::Dumper::Simple; my $stop = qr/[\s:]/; # modify as appropriate! my @lines; my $pattern; ## test one.. @lines = split /\n/, <<'EOD'; Error 123 on SystemA file not found error Error 123:on SystemB file not found error Error 123 on SystemC file not found error EOD $pattern = get_pattern( \@lines ); print Dumper($pattern); ## test two.. @lines = split /\n/, <<'EOD'; Error 124 on User1:FileA no space left Error 124 on User2:FileB no space left Error 124 on User3:FileC no space left EOD $pattern = get_pattern( \@lines ); print Dumper($pattern); sub get_pattern { my @lines = @{ +shift }; # this should take a copy.. my @known_words = split /($stop)/, shift @lines; my @pattern = @known_words; # assume everything matches.. my %modified = (); # track indices my $count = 0; # $x incrementor LINE: foreach my $line (@lines) { my @words = split /($stop)/, $line; unless ( @words == @known_words ) { warn "ignoring (word count does not match first line): $li +ne"; next LINE; } WORD: foreach my $i ( 0 .. $#words ) { next WORD if $modified{$i}; # already noted this spot my $this = $words[$i]; next WORD if $this =~ $stop; # questionable.. are all s +tops 'equal'? my $that = $known_words[$i]; next WORD if $this eq $that; # everything looks ok so f +ar $pattern[$i] = '$' . ++$count; $modified{$i}++; } } return join '', @pattern; }
produces:
$pattern = 'Error 123 on $1 file not found error';
$pattern = 'Error 124 on $1:$2 no space left';
(updated to move 'my $count' to proper scope)

In reply to Re: String similarities and pattern matching by mreece
in thread String similarities and pattern matching by Phalcon123

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.