undef $/; # to absorb the whole file in a single read. open FILE, $filename; $all = ; $all =~ s/\.html/\.asp/g; # this will substitue the .html to .asp globally # this takes the part in between the body tags... $all =~ s{^.*?\(.*)\.*?$} {$1}isx; print OUTFILE $all; close FILE;