my ($var) = $filecontents =~ /SOME_REGEX(.*?)$/g; if (defined $var) { ... proceed w/ usage of $var }