http://www.perlmonks.org?node_id=1025093

iang has asked for the wisdom of the Perl Monks concerning the following question:

I have to extract a hostname from a fqdn, however it is possible that the fqdn is simply a hostname. so for host.foo.bar.com, I want to split (host,domain). and for host , I want to split, but domain should be null. I realize that I can do this with split, but I wanted to try a regex. My code is like this:
if($file =~ m/hd_defect-(.*?)\.(.*)$/) { $host = $1; $dom = $2; }
this does not work for a simple host, so I added a modifier:
if($file =~ m/hd_defect-(.*?)\.?(.*)$/) { $host = $1; $dom = $2; }
But that does not work either. Any pointers would be appreciated. Thanks