use strict; use warnings; my $counter; open(FILE,") { if ($_ =~ /(:.*\()(\w+)/g) { $_ =~ s/$2/mach irgendwas/; } elsif (/(:.*\()\"(\w+)/g) { $_ =~ s/$2/mach irgendwas/; } if ($_ =~ /\(/) { $counter ++; } if ($_ =~ /\)/) { $counter --; } print $_; } close FILE; print "$counter\n";