#!/usr/bin/env perl use strict; use warnings; use Inline::Files; my %seq; while () { my ($trim) = /^\s*(.*?)\s*$/; ($seq{$trim} = $trim) =~ s/\h+/bbb/g; } my $re = qr{(@{[join '|', sort { length $b <=> length $a } keys %seq]})}; while () { s/$re/$seq{$1}/g; print; } __SEQ__ scooped up by social travesty without proper sanitation __TXT__ Many of them are scooped up by chambermaids, thrown into bin bags and sent off to landfill sites, which is a disaster for the environment and a social travesty given that many people around the world are going without proper sanitation. #### Many of them are scoopedbbbupbbbby chambermaids, thrown into bin bags and sent off to landfill sites, which is a disaster for the environment and a socialbbbtravesty given that many people around the world are going withoutbbbproperbbbsanitation.