for (@files) { my @matches = /(.{8}-.{3}-i32)/g; my $last_match = $matches [-1]; print $last_match, "\n"; }