for my $file ("may_07_xsd00544.dat") { open (my $fh,"<",$file) or die "Can't open file $file: $!"; while (my $line = <$fh>) { chomp($line); last if ($line =~ /TOTAL COMMAND SUMMARY/); next if (($line =~ /^[a-zA-Z]/) or ($line =~ /^\s*$/) or ($line =~ /^\s/));