in reply to Modifying 'next' in foreach loop

First, if ( $line =~ /^SY/ ) { s/^SY/CN/ } is redundant. And if you need to keep track of what the "next" line is, set a flag:
my $is_sy; for my $line (@lines) { if ( $is_sy ) { $line =~ s/^SY/ /; $is_sy = 0; } else { $is_sy = ( $line =~ s/^SY/CN/ ); } }