for ( glob path/YYYYMMDD/* ) { my @split = split( '/' ); my $file = pop @split; open my $com, "com -23 $_ path/$prv_bus_day/$file |"; for my $delrow ( <$com> ) { # build the delete statement from $delrow } close $com; }