# don't bother $_; use $source directly as loop variable while ( my $source = ) { # skip blank lines; no need for capturing () next if $source =~ m/^\s*$/; # compare fixed strings directly without regex; use operators eq or ne if ( substr( $source, 145, 16 ) eq 'Page: 1' ) { $page1 = 1; } elsif ( substr( $source, 76, 11 ) eq 'Run Listing' ) { $reporttype = 1; } elsif ( substr( $source, 72, 9 ) eq 'Sorter: 2' ) { # no need for $sorter2; just check the other variables and do your stuff if ( $page1 == 1 and $reporttype == 1 ) { # just personal preference; post increment $dcount++; # personal preference; print a list instead of concatted strings print substr( $source, 83, 20 ), "\n"; $page1 = 0; $reporttype = 0; # leave out next, if there is no more code in the while-loop #next; } } # no other stuff here? }