in reply to Unable to find my mistake
use strict; use warnings; my $par_value = 3; my $inData = <<INDATA; wire [130 : 0] dgrs_1; wire [130 : 0] dgrs_2; wire [130 : 0] mgs_1; wire [130 : 0] mgs_2; wire [130 : 0] pqr_1; wire [130 : 0] pqr_2; int abc; int pqr_1; int pqr_2; .dgrs_1(dgrs_1); .dgrs_2(dgrs_2); .mgs_1(mgs_1); .mgs_2(mgs_2); INDATA open my $in_fh1, '<', \$inData; while (my $line = <$in_fh1>) { if ($line =~ m{ \A (.*dgrs) }xms) { print "${1}_$_;\n" for 1 .. $par_value; } if ($line =~ m{ \A ("\.dgrs") }xms) { print "${1}_$_;\n" for 1 .. $par_value; } if ($line =~ m{ \A (.*mgs) }xms) { print "${1}_$_;\n" for 1 .. $par_value; } if ($line =~ m{ \A (.*pqr) }xms) { print "${1}_$_;\n" for 1 .. $par_value; } elsif ($line !~ m/(?:dgrs|mgs|pqr)/) { print $line; } } close $in_fh1;
seems sufficient to reproduce your problem. Check your regular expressions are matching what you expect them to.
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
In Section
Seekers of Perl Wisdom