use warnings; use strict; use Cwd; my $dir=getcwd; print "$dir\n"; opendir DIR, $dir or die "cant open dir"; my @files = grep /mlx/,(readdir DIR); closedir DIR; foreach my $file (@files) { open(INF, $file) or die "cannot open $file: $!\n"; my $fdata=join("", ); close INF; ##... while ($fdata=~m{(\n)(.*?)(<\/ce:bib\-reference>)}sg){ my $bib=$1; my $label=ExtractAuth($&); $fdata=~s/(\Q$bib\E)/$1$label/; } print "$fdata"; } sub ExtractAuth{ my $bib=shift; my $auth=""; my $label=""; ##... while ($bib=~m{(.*?)<\/ce:textref>}sg){ $auth=$1; if ($auth=~m{\(\d{4}[A-z]?\)}){ my $count= ($auth =~ tr/\,//); $label=AddLabel($auth,$count); #$bib=~s/(\n)/$1$label/; }else { $label="Year Not Found\n"; #$bib=~s/(\n)/$1$label/; } } #$bib=~s/(\n)/$1$label/g; return ($label); } sub AddLabel{ my $auth=shift; my $count=shift; my $fauth=""; my $year; my $labelst=""; if ($count<=1){ if ($auth=~m{(.*?)(\(\d{4}[A-z]?\))}){ $fauth=$1; $year=$2; $fauth=~s/\s$//; $labelst="$fauth\, $year<\/ce:label>\n"; } } return ($labelst); }