if (my ($foo, $bar, @reg_groups) = $string =~ /^(.*?)($regexp)/) { # $foo = $1, $bar = $2, @reg_groups = all the matching groups from $regexp my $totength = length $foo.$bar; my $foolength = length $foo; # whatever happens next }