my @dlcopy = @dir_list ; my @extensions = qw(zip log whatever) ; my %matches ; foreach my $ext (@extensions) { my $nonmatching = [] ; my $matching = [] ; my $code = q| foreach my $file (@dlcopy) { push @{$file =~ /\\.|.$ext.q|$/ ? $matching : $nonmatching},$file ; } | ; # warn "DEBUG:$code" ; eval $code ; if ($@) { die "Something went wrong: $@" ; } else { @dlcopy = @$nonmatching ; $matches{$ext} = $matching ; } }