#!/usr/bin/perl use strict; my $file = "abc*.xml*"; my $searchdir = "/tst"; readDirectory($searchdir, $file); sub readDirectory { my $searchdir = shift; my $searchfile = shift; print "Searching in $searchdir \n"; # Open and close the directory opendir DIR, $searchdir or die("An error occured: $!"); my @files = readdir(DIR); closedir DIR; foreach my $currentFile (@files) { next if $currentFile =~ /^\./; if ( $currentFile eq $searchfile ) { print "Found the file: $searchdir/$currentFile n"; unlink($file); } if ( -d "$searchdir/$currentFile" ) { readDirectory("$searchdir/$currentFile", $searchfile); } } }