while () { my $currentURI = $_; chomp($currentURI); my @tags = eval { # Use eval to make this safe, $@ will contain any error $c->posts_for(uri =>"$currentURI"); } my $error = $@; if (defined($error)) { warn($error); # If eval failed, warn and skip to next line next; } if (! @tags) { next; # Assuming no tags means go to next line in input } ... do something ... }