use strict; sub tagheader { my $header; open(STYLESHEET,'stylesheet.txt'); my $tag = shift; ########################################################### # "HEADER" appears before "nm" in the style sheet # Find each "HEADER" in the file and assign $1 to $header # If we find the $tag we're looking for return $header # while () { if (/^HEADER (\d+):/) { $header = $1; } if (/^nm : ($tag)/) { return \$header; } } close(STYLESHEET); } my $body; my $tag; open(FILE,'taggedfile.txt'); open(OUT,">$ARGV[0]"); while() { if (/^\{(\w+)\}/) { $tag = $1; $body = tagheader($tag); # Right here, $_ contains "nm : $tag" from the tagheader() # I see that $_ has been modified by tagheader() # This is my problem and I'm stumped :( s/\{($tag)\}/\{$1:$body\}/; # I want to search and replace the ($tag) with $1:$body # $body will contain a number that is assigned to the $tag # in the style sheet. } print OUT $_; } close(FILE); close(OUT); __DATA__ FILE { type : if } FILEHDR { File_Comment : "" } HEADER 1: { _std_comment : "" nm : TAG post : "" ppriority : 1st pmaxwhite : 0 } BODY 1:1 { endval : page priority : 1st ffamily : 2 fvariant : 3 fheight : 10q fwidth : same maxwhite : 0 prelead : no ldasc : normal lindent : 0 pgindent : 0 lnmeas : full ldextra : 2q lddesc : normal qdtbl : l hjtbl : 4 pgsplit : no lpabove : 0 lpbelow : 0 laabove : 0 labelow : 0 language : 1 xpath : "" capmode : no kernnum : 1 spotcolor : normal psrnum : 1 ipcrnum : active pair_kern : yes endstring : "" pre : "" repeat : repeat pgrful : none httbl : none pattern : none comment1 : "" }