G'day yunfei,
Welcome to the monastery.
Please provide a self-contained piece of code which reproduces your problem. (Guidelines for doing this can be found in: How do I post a question effectively?)
The following code simulates what you're describing but does not reproduce the problem.
#!/usr/bin/env perl
use strict;
use warnings;
while (my $file = <DATA>) {
print '-' x 60, "\n";
chomp $file;
print "******processing <<<<${file}>>>\n\n";
if ($file =~/(zip$)|(gz$)|(tar$)|(bz$)|(bz2$)/i) {
print "IF: $file\n";
}
elsif ($file =~/md5$/i) {
print "ELSIF: $file\n";
}
print '-' x 60, "\n";
}
__DATA__
/home/user/projects/database/bwa/index_bwa_human_b36_both.fasta.tar.gz
/home/user/projects/database/bwa/index_bwa_human_b36_both.fasta.index.
+tar.gz.md5
Output:
$ pm_weird_print.pl
------------------------------------------------------------
******processing <<<</home/user/projects/database/bwa/index_bwa_human_
+b36_both.fasta.tar.gz>>>
IF: /home/user/projects/database/bwa/index_bwa_human_b36_both.fasta.ta
+r.gz
------------------------------------------------------------
------------------------------------------------------------
******processing <<<</home/user/projects/database/bwa/index_bwa_human_
+b36_both.fasta.index.tar.gz.md5>>>
ELSIF: /home/user/projects/database/bwa/index_bwa_human_b36_both.fasta
+.index.tar.gz.md5
------------------------------------------------------------
In your while(<DBNAME>) {...} loop, it would be useful to show the raw data before and after modification as well as how that ties in with $file="$dir/$file";.
Also, please correct the typo in the title: s/wired/weird/