#!/usr/bin/perl use strict; use warnings; use Data::Dumper; sub get_new_htmls { my $path = shift; opendir (my $dh, $path) or die "Unable to open $path: $!"; my @files = map { $path . '/' . $_ } grep { !/^\.{1,2}$/ } readdir ($dh); # Rather than using a for() loop, we can just # return a directly filtered list. return grep { (/\.html$/) && (! -l $_) } map { -d $_ ? get_new_htmls ($_) : $_ } @files; } my @returned_files = get_new_htmls("/home/tinyos/Monks"); print Dumper \@returned_files; __END__ perl test.pl $VAR1 = [ '/home/tinyos/Monks/index.html' ]