$\ = "\n"; my $s = 'abcdefghij'; $s =~ s/def/123/; print $&; # def print substr($s, $-[0], $+[0] - $-[0]); # 123