my ($x,$y) = $foo =~ /(hello)(world)/ or die "failed to match"; if ( my ($x,$y) = $foo =~ /(hello)(world)/ ) { print $x, $y; } if ( $foo =~ /(?hello)(?world)/ ) { print $+{x}, $+{y}; }