#!/usr/bin/perl -l $s = "\bt\b\bhello"; sub smack { $a = $s; $a =~ s/^\cH+//; 1 while ($a =~ s/[^\cH]\cH//g); $a; } sub othersmack { $a = $s; 1 while ($a =~ s/[^\cH]\cH//g); $a =~ s/^\cH+//; $a; } print smack(); print othermack(); print "smack correct" unless grep {ord==ord"\b"} split//,smack(); print "othersmack correct" unless grep {ord==ord"\b"} split//,othersmack(); __END__ output: hello hello othersmack correct