#!/usr/bin/perl use strict; use warnings; # 839761 my @foo=("a.jpg", "b.txt", "Cde.jpg", "abc.jpg.delete_everything.exe", "123.jpg", "|#&.exe"); print "Using negative match, '!~'- items which match should be excluded:\n\n"; for my $item(@foo) { if ($item !~/^[A-Z0-9]+\.jpg$/i) { print "\t--> (negated) match: $item \n"; }else{ print "no match in \$item: $item \n"; } } print "\n\n". 'Now using /^[A-Z0-9]+\..+$/i' . " so matched should be accepted: \n\n"; for my $item(@foo) { if ($item =~/^[A-Z0-9]+\.jpg$/i) { print "\t --> match: $item \n"; }else{ print "no match in \$item: $item \n"; } }