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. #### scooped up by social travesty without proper sanitation #### use strict; use warnings; use autodie; open Newfile ,">./Newfile.txt" or die "Cannot create Newfile.txt"; my %rep; my ($f1, $f2) = ('seq.txt', 'mytext.txt'); open(my $fh, $f1); my @seq; foreach (<$fh> ) { chomp; s/^\s+|\s+$//g; push @seq, $_; } close $fh; @seq = sort bylen @seq; # need to sort @seq by length. open($fh, $f2); foreach (<$fh> ) { foreach my $r (@seq) { my $t = $r; $t =~ s/\h+/bbb/g; s/$r/$t/g; } print Newfile; } close $fh; close Newfile ; exit 0; sub bylen { length($b) <=> length($a); }