#!/usr/bin/perl
use strict;
use warnings;
my @lines = split /\n/, <<'END';
begin{verbatim}
hello all
end{verbatim}
END
s{((?:begin|end))\{verbatim\}}{$1\{whatever\}} for @lines;
print "$_\n" for @lines;
__END__
poletti@Polebian:~/sviluppo/perl/pwc/tmp$ perl bug.pl
Use of uninitialized value in substitution iterator at bug.pl line 11.
Use of uninitialized value in substitution iterator at bug.pl line 11.
hello all
####
$1\{whatever\}
####
#!/usr/bin/perl
use strict;
use warnings;
my @lines = split /\n/, <<'END';
begin{verbatim}
hello all
end{verbatim}
END
s{((?:begin|end))\{verbatim\}}[$1\{whatever\}] for @lines;
print "$_\n" for @lines;
__END__
poletti@Polebian:~/sviluppo/perl/pwc/tmp$ perl nobug.pl
begin{whatever}
hello all
end{whatever}
####
#!/usr/bin/perl
use strict;
use warnings;
my @lines = split /\n/, <<'END';
begin{verbatim}
hello all
end{verbatim}
END
my %hash = (whatever => 'world');
s{((?:begin|end))\{verbatim\}}{$hash{whatever}} for @lines;
print "$_\n" for @lines;
__END__
poletti@Polebian:~/sviluppo/perl/pwc/tmp$ perl bug2.pl
world
hello all
world