#!/usr/bin/perl use warnings; my $html = shift; my $htmlvar; open(my $fh, '<', $html) or die "cannot open file $html"; { chomp; local $/; $htmlvar = <$fh>; } close($fh); my $line = 1; while (){ chomp; if ($htmlvar =~ /$_/ && $htmlvar !~ /$_<\/sentence>/){ $htmlvar =~ s/($_)/$1<\/sentence>/; $line++ } } print "$htmlvar\n";