if(my ($m1) = $output =~ /^(pattern1)$/ or my ($m1) = $output =~ /^(pattern2)$/ or my ($m1) = $output_2 =~ /(pattern3)/) { $hash{$key} = $m1; }