foreach my $item (@theseContents) { if (!($item =~ /\.zip$/)) { if (!($item =~ /^\./)) { my $temp = $thisDirectory.$item; if (-d $temp) { ....... } } } } #### foreach my $item(@theseContents){ next unless ($item =~ /\.zip$/); next unless ($item =~ /^\./); ..... rest_of_code ...... } #### my $file = shift; #grab the first arg to the sub my $todayfile = sprintf("%02d%02d%02d\.log", $times[5]-100,$times[4]+1, $times[3]); #then your exit routine