my $string = "This is that is other is"; my %hash; if ( @hash{'a', 'b', 'c'} = $string =~ m/(This).+(that).+(other).+/ ) { print "$_ = $hash{$_}\n" foreach keys %hash; }