my $input = $q->param('input'); my $Num =~ m/^\d{6,6}\.jpg$/i; chdir('/path/to/images') or die $!; @files = File::Find::Rule->file() ->name(qr{$Num}) ->in($imageDir); print $q->header(); foreach my $image (@files){ unless ($input){ next; } if($image =~ /$input/){ print $image; } else{ print "$input does not exist!\n"; } }