# Warning: untested code... while (<>) { # Find the timetable and count the +---...---+ lines if ($hit= /Bus timetable/ .. $eot_count==3) { if ($hit==1 || $hit=~/e0/i) { # reset counters $eot_count=0; $line=0; } elsif (/\+\-{20}\+\-{12}\+\-{11}\+\-{6}\+/) { # count +----...---+ lines ++$eot_count; } # count lines inside the table if ($eot_count==2) { if (++$line==4) { # found fourth line... } } } }