#!/usr/local/bin/perl use strict; use warnings; my $address= "name=domainname.domain.dot.com"; #the command output $address =~ s/name=//; print "$address\n"; my ($domainname, $domain)= $address=~ /(\w+)\.(\w+)\./; print "$domainname\n"; print "$domain\n";