#!/usr/bin/perl use strict; use warnings; my $filename = "last.pl"; open(SOMEFILE, $filename) or die "Could not open file $filename"; LINE: while () { # if the text contains the special word, then exit the loop last LINE if ( /BOMB/ ); print "LINE: $_"; } close(SOMEFILE);