#!/usr/bin/perl -- use warnings; use strict; use feature qw{ say }; use File::Which qw/ which /; our $GOTPS = which('ps'); say $$; psMem(); my $file = shift; open my $FH, '<', $file or die $!; my $string; { local $/; $string = <$FH> }; say length $string; psMem(); undef $string; psMem(); seek $FH, 0, 0; $string = do { local $/; <$FH> }; say length $string; psMem(); undef $string; psMem(); sub psMem { my( $pid ) = @_; my @lines = qx{$GOTPS -o vsize,rss -p $pid }; chomp @lines; foreach my $line (@lines) { my ( $vsize, $rss) = split /\s+/, $line; return "VM: $vsize RSS: $rss "; } return; }