#!/usr/bin/perl

my $str = "fooFOOfOoFoOBARBARbarbarbAr";
$str =~ s/(?i:foo)|BAR/<$&>/g;
print $str;