If the positions of all the characters are very strict you may be able to write a program to determine those positions. Once you have those positions you could proceed with parsing the 'scan' lines. Here is a small code excerpt that you could use:

use strict ; use warnings ; my @pins = qw(31 22 13 84 95) ; my @positions = (40,42, 44, 46, 48) ; while (<DATA>) { my $line = $_; my $scan ; my $offset ; if ( $line =~ /(scan\d+)\s*(\d+)/ ) { $line = $line . <DATA> ; $scan = $1 ; $offset = $2 ; } for my $i (0..$#positions) { $_ = $positions[$i] ; my $pin = "p" . $pins[$i] ; if ( $line =~ /^.{$_}([HL]).*?\n.{$_}[\^]/ ) { print "$scan $offset $pin $1\n" ; } } } __DATA__ scan1 2965 H L H L H ^ scan2 2200 L H H L H ^ scan3 1100 H L L L L ^ scan4 1500 L L H H H ^ scan5 2800 H H L H H ^ ^

Output:

scan1 2965 p13 H scan2 2200 p22 H scan3 1100 p22 L scan4 1500 p13 H scan5 2800 p22 H scan5 2800 p95 H

In reply to Re: Perl script to match a regexp in the prior line and other multiple lines by Veltro
in thread Perl script to match a regexp in the prior line and other multiple lines by kshitij

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.