The following script also produces similar results: perl -e 'my $x = q[if ($h->{ALPHA}->{BETA}->{q{stuff}}) {] . "\n" . q[ stuff($h, @_);] . "\n}\n\n"; $x x= 7238; $x =~ s/stuff/"stuff" . ++$count/eg; eval $x' Adjusting the x= XXXX makes a bit more flexible test case. 7238 doesn't crash, but 7239 does.