Dude, that's a bit of a convoluted way to go about it. How about keeping it simple? cat file | sed "s/<div>/<p>/g" | sed "s/<\/div>/<\/p>/g" > newfile -- “Don't eat anything you've ever seen advertised on TV” - Michael Pollan, author of "In Defense of Food"