in reply to flag function

Hello dideod.yang,

Fellow Monks have answered your question but I wanted to add another possible solution, not more efficient but just for fun. See sample of code bellow:

#!/usr/bin/perl use strict; use IO::All; use warnings; use Data::Dumper; use List::Util 'first'; my @lines = io($ARGV[0])->chomp->slurp; print Dumper \@lines; my $match = first { /test/ } @lines; print 'First Found: ' . $match . "\n"; __END__ $ perl sample.pl file.txt $VAR1 = [ 'This is line one', 'This is line two', 'This is line three with test key word', 'This is line four with test key word' ]; First Found: This is line three with test key word

I am using the following two modules IO::All and List::Util::first. The first modules it is loading the lines on an array, the second module will stop searching the array when it will find the first match.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!