my $is_sy; for my $line (@lines) { if ( $is_sy ) { $line =~ s/^SY/ /; $is_sy = 0; } else { $is_sy = ( $line =~ s/^SY/CN/ ); } }