my @temp; for ( reverse @{[ split( '', $string ) ]} ) { last if /\./; unshift @temp, $_; } $extension = join '', @temp;