Q:

Perl regex - remove first part of dot-separated string

I have to remove the first part of a dot-separated string. Such as:
test.domain.com          --> domain.com
sub.domain.example.com   --> domain.example.com
bar.foo.bar.hoster.net   --> foo.bar.hoster.net

and so on...
How to do this in perl?

A:

The easiest way is to use a substitution like this:
$str =~ s/^[^.]*\.//;

The regex means:

^ - beginning of string
[^.]* - 0 or more characters that are not .
\. - a literal dot

There's no need to capture the rest of the string just to replace it back in.

This code assumes that if there are no dots in the string, you want to leave it unchanged.
However, if you want "foo" to turn into "", you just need to make the \. optional:
$str =~ s/^[^.]*\.?//;

