if($outfile =~ /\.txt$/){ #hat schon .txt am ende }