#!/usr/bin/perl use strict; use warnings; use Data::Dumper::Concise; use File::Grep qw(fgrep); my $start_dir = '/root/Desktop/server1/tools'; my $filename = 'load.c'; opendir(DIR, $start_dir) or die "Could not open $start_dir\n"; my @xml_files = grep(/\.xml$/, readdir DIR); closedir DIR; print "XML FILES: ", "\n"; foreach my $xml_files(@xml_files) { print $xml_files, "\n"; } open(STDOUT, '>', $start_dir); my @filematches = fgrep{ /^$filename$/ } glob "/root/Desktop/server1/tools/*.xml"; print STDOUT $_ foreach Dumper(@filematches); close STDOUT;