sub processReplacements { my ( $regexM, # TERM(S) TO MATCH $regexR, # REPLACEMENT TERM $regexI, # FLAG FOR CASE-INSENSITVE SUBSTITUTION $sv, # $sv => START, E.G. /^(.*)/; $ev, # $ev => END, E.G. /(.*)$/; $ww, # $ww => WHOLE-WORD, E.G. /\b(.*)\b/; $ch, # $ch => DELIMIT CHARS, # E.G. /[.,:;!?'"](.*)[.,:;!?'"]/; @data ) = @_; # INCOMING ARRAY my @changed; # OUTGOING ARRAY my $linehead = ''; my $sourceline = ''; $regexM = decode( 'utf8', $regexM ); $regexR = decode( 'utf8', $regexR ); my $regex = '(?' . ( $regexI ? 'i' : '' ) . ':' . ( $sv ? '^' : $ww ? '\b' : '' ) . ( $ch ? "[$ch]" : '' ) . $regexM . ( $ch ? "[$ch]" : '' ) . ( $ev ? '$' : $ww ? '\b' : '' ) . ')'; foreach my $line ( @data ) { chomp $line; $line =~ s/\s+$//; $linehead = $1 if $line =~ s/((?:\d+\t)+)//; # KEEP A COPY OF ORIGINAL FOR LATER COMPARISON $sourceline = $line; $line =~ s/$regex/$regexR/ge; if ( $line ne $sourceline ) { push @changed, "$linehead$sourceline\t$line\n"; } $line = $linehead . $line; } return @changed; } # END SUB processReplacements