#!/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