The error i am getting: syntax error at D:\testing\pract.pl line 14, near "[^" Execution of D:\testing\pract.pl aborted due to compilation errors. #### use strict; use warnings; my %imlre = ('RE1' => ['RE1', 'body', 'measure', 'remove'], 'RE2' => ['RE2', 'jcode', '', 'remove']); my $input = 'front matter comes herebodymatter comes hereback matter'; for (keys %imlre) { if ($imlre{$_}->[3] =~ /^remove$/i) { $input =~ s/<$imlre{$_}->[1][^>]*>//g ; #here getting error #$input =~ s/<$imlre{$_}->[1]([^>]*)>//g ; #here no error } } print $input;