#!/usr/bin/perl use strict; use warnings; use Try::Tiny; sub normal { open my $normal , ">" , "normal.txt" or die $!; print $normal "This is just a sample\n"; close $normal or die $!; } normal(); sub handle { open my $handle , ">" , "handle.txt"; my $open = try { die $!; } catch { warn "caught error: $_"; # not $@ }; print "\$open: ".$open."\n"; print $handle "This is another sample\n"; close $handle; my $close = try { die $!; } catch { warn "caught error: $_"; # not $@ }; print "\$close: ".$close."\n"; } handle(); __END__ caught error: Inappropriate ioctl for device at try::tint.pl line 22. $open: 1 caught error: Inappropriate ioctl for device at try::tint.pl line 33. $close: 1