#! perl -slw use strict; my $search_string = 'uekasdh'; # Split the search string into chars and intersperse # them with the "ignore whitespace" regex. my $re = join '\s*', split '', $search_string; my $data = do{ local $/; }; # Slurp the data $data =~ s[$re][jjjjjjjj]; # Find and replace. print $data;