$ext="\.htm"; if($file=~ /$ext$/){ #Extension is at end of file # The final $ matches the end of the string. } #### if((index ($filename, $ext) + 1 + length($ext))==length($filename)){ #Extension was at end of $filename #Untested, I might be off by one }