in reply to how to get the String as regularexpression

Already reneeb++ and ptum++ has given solutions to solve your problem.

In addition to that, if you are getting the list of files from directory, you can use '$' anchor at the end in the matching regex ($exten) to avoid files matching '.xml.bak', '.doc.bak' etc. I think this ll help you.

use strict; use warnings; my $exten = '(\.txt|\.csv)$'; my @files = ('one.txt.bak', 'two.html', 'three.csv', 'four.log', 'five +.txt'); foreach (@files) { if (/$exten/) { print $_, "\n"; } } prints: three.csv five.txt

This won't match 'one.txt.bak'.

updated: added code

Prasad