my $filename = "/home/root/this_is_a_valid_name.html.gz"; if ($filename =~ /(\.(?:htm|html|txt|pdf|ppt|csv|doc]))\b/i) { print "match\n"; # this will print }