#!/usr/bin/perl use strict; use warnings; opendir(DIR, "."); my @list = readdir(DIR); closedir(DIR); foreach my $file (@list){ #the line below makes sure you don't try to open . and .. if($file !~ /^\.+$/){ open(FILE,"$file"); my @lines = ; close FILE; # Open same file for writing, reusing STDOUT open (FILE, ">$file") or die "Can't open $file: $!\n"; # Walk through lines... foreach my $line ( @lines ) { #can just make the replacement on this line $line =~ s/(\w+_[_\w]+)\(\)/$1\(\)<\/A>/; print FILE $line; } close FILE; } } closedir( DIR );