#!/usr/bin/env perl use strict; use warnings; use Path::Tiny; chomp (my @SetBCs = ); for my $fname (@SetBCs) { next unless $fname; my @command = grep {/Sets/ .. /Rules/} path ($fname)->lines; print @command; } __DATA__ C:/ProcessFiles/File1.txt C:/ProcessFiles/File2.txt C:/ProcessFiles/File3.txt C:/ProcessFiles/File4.txt C:/ProcessFiles/File5.txt