# - handle some pre-processing # $FILE contains a safe path to an existing file on # the filesystem, based on browser input. open( my $fh, '<', $FILE ) or die "open failed: $!"; my $file = do { local $/; <$fh> }; close( $fh ); my ($needed) = $file =~ /\A/s; # now output the document, using the $needed info. #### BEGIN { use vars qw($NEEDED); } # as in first example. unless (exists $NEEDED{$FILE}) { open( my $fh, '<', $FILE ) or die "open failed: $!"; my $file = do { local $/; <$fh> }; close( $fh ); ($NEEDED{$FILE}) = $file =~ /\A/s; } # now output the document, using the $NEEDED{$FILE} info.