#!/usr/bin/perl use strict; use warnings; use IO::All; use Data::Dumper; my @files = io('fileName.txt')->chomp->slurp; print Dumper \@files; __END__ $ perl test.pl $VAR1 = [ 'a.txt', 'b.txt', 'c.txt' ]; #### #!/usr/bin/perl use strict; use warnings; use IO::All; use Data::Dumper; sub grepFileFromSubroutine { my @files = io(shift)->chomp->slurp; my @final; foreach my $file (@files) { if ( -e $file ) { # double check existence my @lines = io($file)->chomp->slurp; # Chomp as you slurp if (my @matches = grep( /string/, @lines ) ) { push @final, "Found in File: '$file':", @matches; } } } return \@final; } print Dumper grepFileFromSubroutine(@ARGV); __END__ $ perl test.pl fileName.txt $VAR1 = [ 'Found in File: \'a.txt\':', 'Line two interested, string', 'Found in File: \'b.txt\':', 'Line one interested, string', 'Line two interested, string' ]; __DATA__ $ cat a.txt b.txt c.txt Line one not interested Line two interested, string Line one interested, string Line two interested, string Line one not interested Line two not interested Line three not interested