use strict; use warnings; my $MATCH_THIS = q(aa); my @filenames = qw(file1:aa file2:bb file3:cc file4:AA); for my $fn (@filenames) { print "Matched $fn\n" if $fn =~ /$MATCH_THIS/i; } #### Matched file1:aa Matched file4:AA