On Thu Aug 28 01:53:46 2003, vparseval wrote: > #! /usr/bin/perl -w > > package Tie::Prematch; > sub TIEHASH { bless \my $dummy => __PACKAGE__ } > sub FETCH { return substr $_[1], 0, $-[0] } > > package main; > > tie my %pre, 'Tie::Prematch'; > my $foo = "foobar"; > $foo =~ s/.ob/$pre{ $foo }/; The problem here is that the Perl compiler sees the RHS of the s/// as being invariant and thinks it can get away with evaluating without setting up the last-match context. At the optree level the difference is the inclusion or otherwise of the substcont OP code. Since this is a compile time optimisation and the tied-ness of %pre cannot be determined at compile time there's not much that can really be done to fix this (other than ditch the optimisation completely - which would be a very high price to pay). Arguably this (c|sh)ould be documented in perlop and/or perltie.