Fill_List( '/dir', '^error' ); sub Fill_List { my $dir = shift; my $match = shift; my @found; opendir DIR, $dir or die "Cannot open directory $dir: $!"\n; while( defined( my $file = readdir(DIR) )) { push @found, $file if $file =~ /$match/o; } close DIR; return @found; }