#!/usr/bin/perl use strict; use warnings; my $_; my $name1; my @wds; open(my $WorteFh, '>', 'Worte.TXT' ) or die $!; my @txtfiles = glob( "*.txt" ) or die $!; for my $file ( sort @txtfiles ) { open( my $fh, '<', $file ) or next; local $/; my $content = <$fh>; close $fh; my $words = 0; if ($content =~ m{ (\n) \.SUBCKT \b }mix )# Test ob .Subckt enthalten { if ($content =~ m/^\.subckt ([\w.\s]+)/im) # Wenn ja, alles nach .Subckt auslesen { $name1 = $1; (undef, my @wds) = split(/ /,$name1); next unless @wds; print join "; ", @wds; print "\n"; $words += scalar(@wds); print("words=$words\n"); print "$file\n$name1\n"; print $WorteFh "$words\n"; } } } close $WorteFh;