use strict; use warnings; open my $fh, '<', $ARGV[0] or die "Cannot open file '$ARGV[0]' for reading: $!"; sub getsub { my ($sub) = @_; print "inside sub for $sub\n"; seek $fh, 0, 0; (/\.subckt $sub/ .. /\.ends/) && print while <$fh>; } my $line = <$fh>; while ($line) { if ($line =~ /^xa1/) { print "line found to be $line\n"; my $next; $line = $next while !eof && ($next = <$fh>) =~ /^\+/; $line =~ s/\s+$//; my $sub = (split /\s+/, $line)[-1]; print "subcircuit found is $sub in $line\n"; my $file_pos = tell $fh; getsub($sub); seek $fh, $file_pos, 0; $line = $next; } else { $line = <$fh>; } } close $fh or die "Cannot close file '$ARGV[0]': $!";