my @str = qw/ a.jpg b.gif c.png d.txt e.jpeg a.jpg.3 /; for my $str (@str) { if ($str =~ /.*?\.(?!gif|jpe?g)/) { print "matched: $str\n"; } } __END__ # output is matched: c.png matched: d.txt matched: a.jpg.3