my ($extract) = $string =~ m/(foo)/; # oder if ($string =~ m/(foo)/) { my $extract = $1; }