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