$file="filename.txt"; $ext=".txt"; if ($file =~ /$ext$/){ print "match\n"} else {print "nomatch\n"}