use strict; use warnings; my @images = qw{a.png b.gif c.svg d.blah.jpg ..}; foreach (@images) { my $after_last_dot = (split (/\./,$_))[-1]; $after_last_dot //= ''; print ".",$after_last_dot,"\n"; } __END__ .png .gif .svg .jpg . <=might want something else here?