Q:

Match two strings regardless of whitespace in perl

How can I, given two variables, match a two strings regardless of white spaces?
my $String_1 = "FOO BAR";
my $String_2 = "FOOBAR";

if ($String_1 =~ m/ WHAT GOES HERE? /) {
    print "Match\n";
}

A:

This is neatly done using the translate operator with the non-destructive option tr///r.
This program encapsulates the comparison in a subroutine no_space_compare.
use strict;
use warnings;
use 5.014;     # For non-destructive translate

my $string_1 = "FOO BAR";
my $string_2 = "FOOBAR";

say $string_1 eq $string_2 ? 'match' : 'no match';

say no_space_compare($string_1, $string_2) ? 'match' : 'no match';

sub no_space_compare {
  my ($s1, $s2) = @_;
  $s1 =~ tr/ //dr eq $s2 =~ tr/ //dr;
}

output
no match
match

