open (FH,"filename here") or die; while ( my $line = ) { DO STUFF HERE WITH LINES; last if $line =~ /^END$/; } close(FH);