# Wait for 'MILLISEC' to appear while () { last if /MILLISEC/; } # your current code.... my $findline=3; # with this adjusted to the right value...