while (my $row = <$fh>) { chomp($row); next if $row =~ /^cd|^#|^$/; # skip lines $row =~ /xruntime\/([a-z0-9]+)_/; # regexp pattern matching with memory () print "\t{ \"{#BOBINSTANCE}\":\"$1\"}\n"; # print memory register $1 }