my $offset = -5; # or however many characters from the end # that you want my $new_string = substr $filename, $offset;