Use
qr//. It is used to store a regex in a variable. Think you want something like this.
my $re = qr/.+\-(.+)/;
$foo =~ s/$re/$1/;
but if all are in
domain-computer form, you could just use
$foo =~ s/.+\-(.+)/$1/;
Update:
but on second thought the first way could run in a loop and you could just define the regex before the loop using
qr//. That would probably be more efficient.
Example:
use strict;
my $re = qr/.+\-(.+)/;
while(<DATA>){
s/$re/$1/;
print;
}
__DATA__
domain-comp1
domain-comp2
domain-comp3
Output:
comp1
comp2
comp3