#!/usr/bin/perl -w use strict; my $sect=0; # Not in a section yet while (<>) { if ($sect==1) { if (/(\d+)\s+(.+)\s+(\d+)\s+(\d+)\s*$/) { # Correct section AND format, assumed valid print "Sec1: $1, $2, $3, $4\n"; } else { $sect=0; # Wrong fmt, end of sect assumed } } elsif ($sect==2) { if (/(\d+)\s+(\d+)\s+(.*)\s+(\d+)\s+(\d+)\s+(\d+)\s*/) { print "Sec2: $1, $2, $3, $4, $5, $6\n"; } else { $sect=0; } } elsif (/^team\s+teamname\s+score\s+wu$/) { # Start of team info section $sect=1; } elsif (/^rank\s+team rank\s+name\s+credit\s+total\s+team$/) { # Start of rank info section $sect=2; } else { # Uninteresting line, ignore it... } }