my $first = $1; if (my ($tail) = $line =~ /^\.march_endSP)(.*)/) { print(".rs_$_$tail\n") for 1..$first; } else { print($line); }