#!/usr/bin/perl -T -- use strict; use warnings; use IPC::System::Simple qw' capturex '; Main( 'theuser' ); exit( 0 ); sub Main { my( $username ) = @_; #~ my $top = `top -b -n 1 -u $username`; ## Capture text while invoking the shell. #~ my $top = capturex( qw' top -b -n 1 -u ', $username ); my $output = <<'__TOP_EXAMPLE__'; here is something top will output it goes like this __TOP_EXAMPLE__ if( $output=~ /.../ ){ # my regex print "$1$2...\n"; } }