You can use the 'state' feature' (refer: perldoc perlfunc) rather than the extra block to limit the scope of $last.
use feature 'state';
sub do_stuff {
state $last=999;
my ($arg) = @_;
if ( $arg == $last ) {
print "You called me twice in a row with $arg\n";
}
$last = $arg;
}
do_stuff($_) for 0..5,5;