in reply to Re^2: My regex works, but I want to make sure it's not blind luck
in thread My regex works, but I want to make sure it's not blind luck

Not exactly right to left, but this code looks for a line that ends with a period, followed by at least one character that is not a period before the end of the line or string. The period and characters that follow it are captured. If the match fails, $suffix is set to a null string. You can specify what you want in relation to the end of the string, but this is not "backwards" or right to left - this is the "rightmost" pattern that matches.

use strict; use warnings; foreach my $test ('..', 'file.txt', 'blah.abc.txt') { my ($suffix) = $test =~ /(\.[^.]+)$/; $suffix //= ''; #suffix is null string if no match print "test=$test suffix=$suffix\n"; } __END__ test=.. suffix= test=file.txt suffix=.txt test=blah.abc.txt suffix=.txt
There are many modules like: File::Basename.

Update: I guess probably: my ($suffix) = $test =~ /(\.\w+)$/;
Word characters are A-Za-z0-9_. Space and control chars are not allowed.