while (my $line = <$inputFH> ) { next unless $line =~ m{some pattern}; # Process wanted line here ... last; # Break out of while loop }