$dev_ref->{hostname} = '2383-RWAN-1'; $dev_ref->{grbr } = '2383'; my $pattern = qr{HOSTNAME:\s*(?:\d{4}-)?$dev_ref->{hostname}\s+GRBR:\s*$dev_ref->{grbr}}i; my $buffer = <<'__EOI__'; 9600/ARQ Some Company ---> Unauthorized use of this router is prohibited <--- ******************************************************* * Hostname: 2383-rwan-1 GRBR: 2383 * * Model: Cisco 1234 * * Location: Ansalon , DL * ******************************************************* ---> Unauthorized Access is strictly prohibited <--- User Access Verification Username: __EOI__ my $hostname = $buffer =~ m/$pattern/i ? 1 : 0 ; print($hostname, "\n");