use warnings; use strict; use Data::Dumper; use IPC::Run qw/ run timeout /; use Try::Tiny; my @file_list; try { run ['ls','/tmp'], \undef, \my $lines, timeout(5) or die "ls: \$?=$?"; @file_list = split /\n/, $lines; } catch { die $_ unless /^IPC::Run: timeout/; warn "Timed out"; }; print Dumper(\@file_list);